Commit 29f2b897 authored by 段英荣's avatar 段英荣

modify

parent 65b11f1f
...@@ -137,33 +137,29 @@ class TypeInfo(object): ...@@ -137,33 +137,29 @@ class TypeInfo(object):
return data_list return data_list
def elasticsearch_bulk_insert_data(self, sub_index_name, data_list, es=None): def elasticsearch_bulk_insert_data(self, sub_index_name, data_list, es=None):
if es is None:
es = get_es_list_by_type(self.type)
if not isinstance(es, (list, tuple,)):
es = [es]
index = ESPerform.get_official_index_name(sub_index_name=sub_index_name,index_flag="write")
bulk_actions = []
for data in data_list:
bulk_actions.append({
'_op_type': 'index',
'_index': index,
'_type': self.type,
'_id': data['id'],
'_source': data,
})
es_result = None
if bulk_actions:
for t in es:
try:
es_result = elasticsearch.helpers.bulk(client=t, actions=bulk_actions)
except Exception as e:
traceback.print_exc()
es_result = 'error'
return es_result # assert (es is not None)
# index = ESPerform.get_official_index_name(sub_index_name=sub_index_name,index_flag="write")
# bulk_actions = []
# for data in data_list:
# bulk_actions.append({
# '_op_type': 'index',
# '_index': index,
# '_type': "_doc",
# '_id': data['id'],
# '_source': data,
# })
#
# es_result = None
# if bulk_actions:
# for t in es:
# try:
# es_result = elasticsearch.helpers.bulk(client=t, actions=bulk_actions)
# except Exception as e:
# traceback.print_exc()
# es_result = 'error'
return ESPerform.es_helpers_bulk(es,data_list,sub_index_name,True)
def elasticsearch_bulk_insert(self, sub_index_name, instance_iterable, es=None): def elasticsearch_bulk_insert(self, sub_index_name, instance_iterable, es=None):
data_list = self.bulk_get_data(instance_iterable) data_list = self.bulk_get_data(instance_iterable)
......
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