Elasticsearch"没有添加请求"批量API错误

Mic*_*cah 55 elasticsearch

尝试将批量更新用于ES 1.0.1.

我在Postman内发布以下内容:

URL POSTPUThttp://localhost:9200/_bulk

请求机构:

{ "update" : { "_index" : "test_people", "_type" : "person", "_id" : "1" }} \n
{ "doc" : { "name":"hi", "age":100 }} \n
Run Code Online (Sandbox Code Playgroud)

我有没有尝试过\n.我总是得到

{
    "error": "ActionRequestValidationException[Validation Failed: 1: no requests added;]",
    "status": 500
}
Run Code Online (Sandbox Code Playgroud)

它在使用数据创建时也做同样的事情:

{
  "create": {
    "_index": "test_people",
    "_type": "person",
    "_id": "1"
  }
}
{
  "name": "hi",
  "age": 100
}
Run Code Online (Sandbox Code Playgroud)

更新

我在Mac,PC和Linux上试过这个,我不断得到同样的错误.

Mic*_*cah 112

即使我\n在最后一行,我确实在我的最后一条json线之后有一个完整的回车.

以下工作:

{ "update" : { "_index" : "test_people", "_type" : "person", "_id" : "1" }} \n
{ "doc" : { "name":"hi", "age":100 }}
Run Code Online (Sandbox Code Playgroud)

所以线下面需要一个空"doc"行.


pra*_*upd 19

确实,在文档行之后有一个空白的新行.

在此输入图像描述


Dmi*_*sky 6

如果您使用 cURL,则批量项目的末尾必须有一个空行,并且必须使用--data-binary(而不是 plain -d)。例如,假设您有一个名为的文件bulk,其中包含:

{ "index" : { "_id" : 1 } }
{ "accounts" : ["hillary", "sidney"]}
{ "index" : { "_id" : 2 } }
{ "accounts" : ["hillary", "donald"]}
{ "index" : { "_id" : 3 } }
{ "accounts" : ["vladimir", "donald"]}
Run Code Online (Sandbox Code Playgroud)

确保文件以空行结尾,然后使用 cURL 发布:

curl -i -XPOST -H'content-type: application/json' 'localhost:9200/emails/message/_bulk?refresh&pretty' --data-binary @bulk
Run Code Online (Sandbox Code Playgroud)