Elasticsearch批量索引api通过休息端点

use*_*332 9 elasticsearch elasticsearch-plugin

这是我的要求:

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"}}
Run Code Online (Sandbox Code Playgroud)

这是错误:

{    "error": "IllegalArgumentException[Malformed action/metadata line [3], expected START_OBJECT or END_OBJECT but found
Run Code Online (Sandbox Code Playgroud)

[VALUE_STRING]]","状态":500}

基本上,每个文档都是{"firstname":___,"lastname":____}我不想将它们包装到父字段中.我从根本上缺少什么?

Val*_*Val 14

您只是错过了第二个和第三个文档的操作行,请尝试这样:

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"}
Run Code Online (Sandbox Code Playgroud)

  • [不要重复自己](https://www.elastic.co/guide/en/elasticsearch/guide/current/bulk.html#_don_8217_t_repeat_yourself)部分建议一种避免重复```_index```和``_type```一直都是值.但请注意,必须仍然为每个文档指定*action*. (3认同)