弹性搜索批量忽略了json

时间:2016-12-29 18:21:45

标签: elasticsearch

我正在尝试在弹性搜索中执行批量操作。但是,JSON中给出的最后一次操作永远不会通过弹性搜索执行。

这是我的请求

curl -XPOST 'localhost:9200/customer/external/_bulk?pretty&pretty' -d'

{"update":{"_id":"1"}}
{"doc": { "name": "Update - John Doe becomes Jane Doe" } }

{"delete":{"_id":"4"}}

{"index":{"_id":"3"}}
{"name": "Create or Update - New Jane Doe" }

{"create":{"_id":"4"}}
{"name": "Only Create - New Jane Doe" }

{"create":{"_id":"5"}}
{"name": "Only Create - New Jane Doe 1" }'

响应仅包含4个输出而不是5:

{
  "took": 100,
  "errors": false,
  "items": [
    {
      "update": {
        "_index": "customer",
        "_type": "external",
        "_id": "1",
        "_version": 9,
        "result": "noop",
        "_shards": {
          "total": 2,
          "successful": 1,
          "failed": 0
        },
        "status": 200
      }
    },
    {
      "delete": {
        "found": true,
        "_index": "customer",
        "_type": "external",
        "_id": "4",
        "_version": 4,
        "result": "deleted",
        "_shards": {
          "total": 2,
          "successful": 1,
          "failed": 0
        },
        "status": 200
      }
    },
    {
      "index": {
        "_index": "customer",
        "_type": "external",
        "_id": "3",
        "_version": 7,
        "result": "updated",
        "_shards": {
          "total": 2,
          "successful": 1,
          "failed": 0
        },
        "created": false,
        "status": 200
      }
    },
    {
      "create": {
        "_index": "customer",
        "_type": "external",
        "_id": "4",
        "_version": 5,
        "result": "created",
        "_shards": {
          "total": 2,
          "successful": 1,
          "failed": 0
        },
        "created": true,
        "status": 201
      }
    }
  ]
}

在我的方案中, ID为“5”的客户(名称:“仅限创建 - 新的Jane Doe 1”)从未创建。如果我删除了最后一个请求(id:5),那么即使是id:4也没有被创建。

我进行了搜索以获取客户索引的所有文档,但ID:5不存在。

就好像Elastic搜索忽略了JSON的最后一部分。我甚至试图通过PostmanClient发布请求,但它仍然是相同的。

弹性搜索版本:5.1.1

1 个答案:

答案 0 :(得分:2)

看起来JSON必须始终以新行字符(\ n)结尾,如here所述。

我在JSON末尾添加了一个新行,它运行正常。