Commit a4759e13 authored by 高雅喆's avatar 高雅喆

update

parent 48c8c566
from elasticsearch import Elasticsearch as Es
def get_es():
init_args = {'sniff_on_start': False, 'sniff_on_connection_fail': False,}
new_hosts = [{'host': '172.16.31.17', 'port': 9000}, {'host': '172.16.31.11', 'port': 9000},
{'host': '172.16.31.13', 'port': 9000}]
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
"""
assert rw in [None, 'read', 'write']
index = '-'.join((index_prefix, doc_type))
if rw:
index = '-'.join((index, rw))
return index
def es_query(doc, body, offset, size, es=None):
if es is None:
es = get_es()
index = es_index_adapt(index_prefix='gm-dbmw', doc_type=doc, rw='read')
res = es.search(
index=index,
doc_type=doc,
timeout='10s',
body=body,
from_=offset,
size=size)
return res
def es_mquery(doc, body, es=None):
if es is None:
es = get_es()
index = es_index_adapt(index_prefix='gm-dbmw', doc_type=doc, rw='read')
res = es.msearch(body, index=index)
return res
\ No newline at end of file
import redis
import json
from tool import es_query
from es_tool import es_query
from tool import get_data_by_mysql
......
......@@ -13,7 +13,6 @@ import time
import json
import numpy as np
import pandas as pd
from elasticsearch import Elasticsearch as Es
def send_email(app,id,e):
......@@ -350,41 +349,3 @@ def get_user_log(cl_id, all_word_tags, pay_time=0, debug=0):
return user_df_service
def get_es():
init_args = {'sniff_on_start': False, 'sniff_on_connection_fail': False,}
new_hosts = [{'host': '172.16.31.17', 'port': 9000}, {'host': '172.16.31.11', 'port': 9000},
{'host': '172.16.31.13', 'port': 9000}]
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
"""
assert rw in [None, 'read', 'write']
index = '-'.join((index_prefix, doc_type))
if rw:
index = '-'.join((index, rw))
return index
def es_query(doc, body, offset, size, es=None):
if es is None:
es = get_es()
index = es_index_adapt(index_prefix='gm-dbmw', doc_type=doc, rw='read')
res = es.search(
index=index,
doc_type=doc,
timeout='10s',
body=body,
from_=offset,
size=size)
return res
def es_mquery(doc, body, es=None):
if es is None:
es = get_es()
index = es_index_adapt(index_prefix='gm-dbmw', doc_type=doc, rw='read')
res = es.msearch(body, index=index)
return res
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