How to do Elasticsearch Bulk Insert in Python

6.2k Views Asked by At

I have a JSON array which contains a list of data that needs to be pushed to an ElasticSearch instance. Something like

[ {"Message": "2aTeFCKTYWwfrF"}, {"Message": "2aTeFCKTYWwfrD"}, {"Message": "2aTeFCKTYWwfrW"}.......{"Message": "2aTeFCKTYWwfrG"}]

Now to insert a simple JSON data (like only the element at the first index of this array) from Python into Elasticsearch, here is what I have

url = 'http://localhost:9200/hello/world'
payload = {"Message": "2aTeFCKTYWwfrF"}
response = requests.post(url, json=payload, headers={})

Now if I wanted to insert all the data from the array to the same endpoint using the Bulk API, how would I do it? I don't seem to understand the docs here one bit https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html

0

There are 0 best solutions below