小编che*_*i18的帖子

如何使用Bulk API通过Python将关键字存储在ES中

我必须在ElasticSearch中存储一些与我的python程序集成的消息.现在我尝试存储消息的是:

d={"message":"this is message"}
    for index_nr in range(1,5):
        ElasticSearchAPI.addToIndex(index_nr, d)
        print d
Run Code Online (Sandbox Code Playgroud)

这意味着如果我有10条消息,那么我必须重复我的代码10次.所以我想做的是尝试制作脚本文件或批处理文件.我已经检查了ElasticSearch指南,可以使用BULK API.格式应如下所示:

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_type" : "type1", …
Run Code Online (Sandbox Code Playgroud)

python elasticsearch elasticsearch-bulk-api

56
推荐指数
4
解决办法
6万
查看次数