Python Forum
bulk update in elasticsearch - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: bulk update in elasticsearch (/thread-27555.html)



bulk update in elasticsearch - pythonlearner1 - Jun-10-2020

I am trying to update bulk document to elasticsearch

I am able to update this one by one document

following code works

  
elastic_output = Elasticsearch(output_master, http_auth=(elastic_user, elastic_password), port=9200)

 data_to_update = {
   "doc" : {
   "job": job_rec['job'],
   "site" : job_rec['site'],
   }
  }

elastic_output.update(index="my_index-2020",doc_type='_doc',id=data_to_update['doc']['job'],body=data_to_update)
how do I create bulk json and use bulk update?


RE: bulk update in elasticsearch - pythonlearner1 - Jun-10-2020

I created list something like this by reading data from mongo.
where I am intested in updating record with new value called site


{'_op_type': 'update', '_index': 'my_index-2020', '_id': 314800814, 'doc_as_upsert': True, 'doc': {'job': 314800814, 'site': 'hill'}}
{'_op_type': 'update', '_index': 'my_index-2020', '_id': 314800815, 'doc_as_upsert': True, 'doc': {'job': 314800815, 'site': 'hill'}}

but can't figure out how do I use helper.