使用 nohup 或 disown 如果你要让某个进程运行在后台。

使用Helper.bulk导入json数据时,指定了文档id,会丢数据,试了很多方法都没有用

匿名 | 发布于2018年03月06日 | 阅读数:4545

#打开保存的json文件
with open(self.re_index+'_data'+'.json', 'r',encoding='utf-8' ) as e:
actions = deque()
#遍历
j = 0
for i in e:
action = {
'_op_type': 'index',
'_index' : json.loads(i)['_index'],
'_type' : json.loads(i)['_type'],
'_id' : json.loads(i)['_id'],
'_source' : json.loads(i)['_source']
}
actions.append(action)
print(len(actions))
#bulk多线程请求
for success, info in elasticsearch.helpers.parallel_bulk(es, actions,thread_count=50):
if not success:
print('Doc failed', info)
6w条数据,丢了2千多,但是分区是完整的啊,副本设置了为0都没有用
ES__bulk.jpg
已邀请:

weizijun - elasticsearch fan

赞同来自:

_id是否有重复?
可以_cat/indices?v 看下是否有deleted记录

正道

赞同来自:

之前用的是分页查询后(from...size..),把数据存在本地json文件,可能格式有问题?
后来导出数据用了scroll和scan的方式,解决了问题,不过比之前取数据稍慢了一些
    def get_search_reasult(self, es_search_options, scroll='5m', timeout="1m"):
"""

:rtype: object
"""
es_result = elasticsearch.helpers.scan(
client = self.Es_host,
query = es_search_options,
scroll = scroll,
index = self.re_index,
timeout = timeout
#doc_type = doc_type
)
return es_result

要回复问题请先登录注册