使用Bulk api在elasticsearch 5.1.1中通过cerebro0.4.1插件添加文档

时间:2017-01-04 09:40:41

标签: elasticsearch-5 elasticsearch-bulk-api

当我尝试在cerebro插件中发布以下代码时

POST /_bulk    
    { 
         "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" },
         "field1" : "value1" ,
         "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" },
         "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" },
         "field2" : "value3" ,
         "update" : {"_id" : "1", "_type" : "type1", "_index" : "test"},
         "doc" : {"field3" : "value2"} 
}

在cerebro插件中显示如下错误:

    {
  "error": {
    "root_cause": [
      {
        "type": "action_request_validation_exception",
        "reason": "Validation Failed: 1: no requests added;"
      }
    ],
    "type": "action_request_validation_exception",
    "reason": "Validation Failed: 1: no requests added;"
  },
  "status": 400
}

1 个答案:

答案 0 :(得分:0)

如果你的json正文以新的\n字符结尾,如果有这样的话,该怎么办:

    { "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" }}
    {"field1" : "value1"}
    {"delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" }}
    {"create" : { "_index" : "test", "_type" : "type1", "_id" : "3" }}
    {"field2" : "value3"}
    {"update" : {"_id" : "1", "_type" : "type1", "_index" : "test"}}
    {"doc" : {"field3" : "value2"}}\n

还要确保正确缩进。根据{{​​3}},您应该在json的末尾添加新的换行符。您也可以查看此doc。希望能帮助到你!