简体   繁体   English

如何使用python将批量发布到弹性搜索?

[英]How to post bulk to elastic search using python?

I have to post some information to elastic search using python. 我必须发布一些信息以使用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使用命令将数据发布到搜索服务器

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

Can somebody help me finding alternative way to implement this in python ? 有人可以帮我找到在python中实现此方法的替代方法吗?

Read the json data from your file. 从文件中读取json数据。 Use requests python library to post the json to your server 使用请求python库将json发布到您的服务器

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. 我发现python在这种情况下很有用,此处共享示例。 tryolabs.com/blog/2015/02/17/python-elasticsearch-first-step‌​s. tryolabs.com/blog/2015/02/17/python-elasticsearch-first-step秒。 This could send your single json doc to elasticsearch. 这可能会将您的单个json文档发送到elasticsearch。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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