python 3.x - Elasticsearch-py bulk helper equivalent of curl with file -


i looking replicate following command using elasticsearch python client (and without using subprocess):

curl -s -xpost "localhost:9200/index_name/_bulk" --data-binary @file 

i have attempted use bulk helper without luck:

es = elasticsearch()  open("file") fp:     bulk(         client=es,         index="index_name",         actions=fp     ) 

this results in type missing errors.

the file, processed fine when using curl, looks bit this:

{"index":{"_type":"sometype","_id":"123"}} {"field1":"data","field2":"data",...} {"index":{"_type":"sometype","_id":"456"}} {"field1":"data","field2":"data",...} ... 

please note, i'd rather not change contents of file since have around 21000 same format.

the actions parameter must take iterable (not file handle) iterate on lines of file, need instead:

es = elasticsearch()  def readbulk():     line in open("file"):         yield line  bulk(     client=es,     index="index_name",     actions=readbulk ) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -