I'm new to Elasticsearch. I'm trying to index a json file which contains 100,000+ objects. The format of my json file is:
[{"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":
.....]
This is in the form of a list. The python code I'm using write now to index the file is:
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)
This method is taking a lot of time and is inefficient. The other methods I read needed the file in the format:
{"index": {"_index": "index_name", "_type": "index_type", "_id": "doc_id"}}
{"ingredients:....
Can you suggest an efficient method to index the file?