Adding documents using Bulk api in elasticsearch 5.1.1 through cerebro0.4.1 plugin

853 views Asked by At

When i tried to post the below code in cerebro plugin

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

It is showing error like this in cerebro plugin:

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

There are 1 answers

1
Kulasangar On

What if you have your json body ending up with a new line \n character, which could look something like this:

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

Also make sure that you have your indentation properly. As per the doc, you should be having the new line character at the end of your json. You may have a look at this SO as well. Hope it helps!