Elasticsearch bulk index api via rest endpoint

試著忘記壹切 提交于 2019-12-17 20:06:25

问题


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?


回答1:


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



回答2:


As Samyak says in his comment, "don't repeat yourself". This syntax is tidier.

post /test/_type/_bulk
{ "index": {}}
{"firstname":"first_name1","lastname":"last_name1"}
{ "index": { }}
{ "name": "Test2", "data": "This is my test data2" }


来源:https://stackoverflow.com/questions/32863112/elasticsearch-bulk-index-api-via-rest-endpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!