这是我的要求:
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"}}
这是错误:
{ "error": "IllegalArgumentException[Malformed action/metadata line [3], expected START_OBJECT or END_OBJECT but found
[VALUE_STRING]]"," status":500}
基本上,每个文档都是{" firstname":___," lastname":____}我不想将它们包装到父字段中。我从根本上缺少什么?
答案 0 :(得分: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"}
答案 1 :(得分:2)
正如Samyak在其评论中所说,“不要重复自己”。这种语法比较整齐。
post /test/_type/_bulk
{ "index": {}}
{"firstname":"first_name1","lastname":"last_name1"}
{ "index": { }}
{ "name": "Test2", "data": "This is my test data2" }