在 elasticsearch 5.1.1 中通过 cerebro0.4.1 插件中使用批量 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"} 
}

它在大脑插件中显示如下错误:

    {
  "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
}

如果你的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

还要确保缩进正确。根据文档,您应该在json末尾使用换行符。你也可以看看这个SO。希望对您有所帮助!

相关内容

  • 没有找到相关文章

最新更新