如何将没有 id 的批量插入发送到 elasticsearch

Dam*_*amo 2 elasticsearch

我正在尝试使用批量插入 api 进行弹性搜索。我想插入带有自动生成 ID 的文档,但无论我尝试什么,我都会收到错误。

以下是一些示例:

http://localhost:9200/_bulk
{"create": {"_index": "test", "_type": "_doc"} }
{"user": "kimchy", "post_date": "2002-11-15T14:12:12", "message": "trying out Elasticsearch"}
Run Code Online (Sandbox Code Playgroud)

put 和 post 都会给出错误:

{
  "error": {
    "root_cause": [
      {
        "type": "action_request_validation_exception",
        "reason": "Validation Failed: 1: an id must be provided if version type or value are set;"
      }
    ],
    "type": "action_request_validation_exception",
    "reason": "Validation Failed: 1: an id must be provided if version type or value are set;"
  },
  "status": 400
}
Run Code Online (Sandbox Code Playgroud)

如果我删除 _type _doc 我会收到以下错误:

{
  "error": {
    "root_cause": [
      {
        "type": "action_request_validation_exception",
        "reason": "Validation Failed: 1: type is missing;2: an id is required for a CREATE operation;3: an id must be provided if version type or value are set;"
      }
    ],
    "type": "action_request_validation_exception",
    "reason": "Validation Failed: 1: type is missing;2: an id is required for a CREATE operation;3: an id must be provided if version type or value are set;"
  },
  "status": 400
}    
Run Code Online (Sandbox Code Playgroud)

我通过 docker 使用弹性搜索 6.4.2

~ docker images
REPOSITORY       TAG       IMAGE ID      CREATED      SIZE
elasticsearch    6.4.2     e47ebd7ec3ee  7 weeks ago  828MB
Run Code Online (Sandbox Code Playgroud)

目前通过邮递员发送请求

Val*_*Val 6

如果您想自动创建 id,只需使用index而不是create

change this
    |
    v
{"index": {"_index": "test", "_type": "_doc"} }
{"user": "kimchy", "post_date": "2002-11-15T14:12:12", "message": "trying out Elasticsearch"}
Run Code Online (Sandbox Code Playgroud)