简体   繁体   中英

How to post bulk to elastic search using python?

I have to post some information to elastic search using python. My info looks like

{  "index": {"_type": "TestSuiteReport","_index": "testsuite"}}{"Driver Name": "","Run Mode": "","TestSuite_Starttime": "2016-10-0T14:20:09","TestSuite Link": "2016-10-20T14:20:09","Number Of Tests Passed": 491}

I was using curl for posting the data to my search server using the command

Curl -i -X PUT -k "http://serverip:5601/_bulk" --data-binary @filelocation.

Can somebody help me finding alternative way to implement this in python ?

Read the json data from your file. Use requests python library to post the json to your server

import requests
data = open('yourfile').read()
url = "http://serverip:5601/_bulk"
requests.post(url, data=data)

I found python useful for this scenario and example to that is shared here. tryolabs.com/blog/2015/02/17/python-elasticsearch-first-step‌​s. This could send your single json doc to elasticsearch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM