Elasticsearch bulk index api via rest endpoint

user1189332 picture user1189332 · Sep 30, 2015 · Viewed 9.6k times · Source

Here is my request:

POST /_bulk
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{"firstname":"first_name1","lastname":"last_name1"},
{"firstname":"first_name2","lastname":"last_name2"},
{"firstname":"first_name3","lastname":"last_name3"}}

Here is the error:

{    "error": "IllegalArgumentException[Malformed action/metadata line [3], expected START_OBJECT or END_OBJECT but found

[VALUE_STRING]]", "status": 500 }

Basically, each document is {"firstname": ___, "lastname": ____} I don't want to wrap them into a parent field. What am I fundamentally missing?

Answer

Val picture Val · Sep 30, 2015

You're simply missing an action line for the second and third documents, try like this:

POST /_bulk
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{"firstname":"first_name1","lastname":"last_name1"}
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{"firstname":"first_name2","lastname":"last_name2"}
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
{"firstname":"first_name3","lastname":"last_name3"}