Commit c2ef6bed authored by 李小芳's avatar 李小芳

Merge branch 'add_hauxiang' into 'master'

add

See merge request !6
parents 9bc65516 3ffa9f31
......@@ -69,6 +69,17 @@ def get_es(es_hosts_config=None):
return new_es
def get_service_es(es_hosts_config=None):
init_args = {
'sniff_on_start': False,
'sniff_on_connection_fail': False,
}
new_hosts = settings.ES7_HOSTS_SERVICE if not es_hosts_config else es_hosts_config
new_es = Es(hosts=new_hosts, **init_args)
return new_es
def es_index_adapt(index_prefix, doc_type, rw=None):
"""get the adapted index name
"""
......@@ -99,6 +110,26 @@ def es_query(doc, body, offset, size, es=None):
return res
def es_query_service(doc, body, offset, size, es=None):
if es is None:
es = get_service_es()
index = es_index_adapt(
index_prefix=settings.ES7_HOSTS_SERVICE,
doc_type=doc,
rw='read'
)
res = es.search(
index=index,
doc_type=doc,
timeout=settings.ES7_HOSTS_SERVICE,
body=body,
from_=offset,
size=size)
return res
def has_service(tag_list, content_keyword):
q = dict()
q["query"] = {"bool":
......@@ -111,7 +142,7 @@ def has_service(tag_list, content_keyword):
{"terms": {"closure_tags": content_keyword}}],
"minimum_should_match": 1}}
res = es_query(doc="service", body=q, offset=0, size=1)
res = es_query_service(doc="service", body=q, offset=0, size=1)
if res:
if res['hits']['total'] > 0:
return True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment