【发布时间】:2020-08-05 21:20:54
【问题描述】:
我是 Elasticsearch 的新手。我正在尝试索引一个包含 100,000 多个对象的 json 文件。我的json文件格式为:
[{"ingredients": [{"text": "Butter"}, {"text": "Strawberries"}, {"text": "Granola"}],
"url": "http://tastykitchen.com/recipes/breakfastbrunch/yogurt-parfaits/",
"title": "Yogurt Parfaits",
"id": "000095fc1d",
"instructions": [{"text": "Layer all ingredients in a serving dish."}]},
{"ingredients":
.....]
这是一个列表的形式。 我现在用来索引文件的python代码是:
from elasticsearch import Elasticsearch
es = Elasticsearch([{'host': 'localhost','port': 9200}])
f = open('data.json')
import json
data = json.load(f)
for i in data:
res = es.index(index='food',doc_type='Recipe',id=i["id"],body=i)
此方法耗时且效率低下。我阅读的其他方法需要以下格式的文件:
{"index": {"_index": "index_name", "_type": "index_type", "_id": "doc_id"}}
{"ingredients:....
您能建议一种有效的方法来索引文件吗?
【问题讨论】:
标签: python json python-3.x elasticsearch lucene