我有一堆JSON文件(100),它们被命名为merged_file 1.JSON,merged_file 2。json等等。
如何使用python(elasticsearch\u dsl)将所有这些文件索引到elasticsearch?
我正在使用此代码,但似乎不起作用:
from elasticsearch_dsl import Elasticsearch
import json
import os
import sys
es = Elasticsearch()
json_docs =[]
directory = sys.argv[1]
for filename in os.listdir(directory):
if filename.endswith('.json'):
with open(filename,'r') as open_file:
json_docs.append(json.load(open_file))
es.bulk("index_name", "type_name", json_docs)
JSON如下所示:
{"one":["some data"],"two":["some other data"],"three":["other data"]}
我能做些什么来纠正这个错误?
对于此任务,您应该使用
elasticsearch-py
(pip install elasticsearch
):相关问题 更多 >
编程相关推荐