社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Elasticsearch

如何将没有ID的批量插入发送到ElasticSearch

Damo • 7 年前 • 3233 次点击  

我正在尝试使用Bulk Inset API进行弹性搜索。我想插入带有自动生成ID的文档,但不管我怎么做,都会出错。

以下是一些例子:

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

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
}

如果我删除“类型”文档,我会得到以下错误:

{
  "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
}    

我正在通过Docker使用弹性搜索6.4.2

~ docker images
REPOSITORY       TAG       IMAGE ID      CREATED      SIZE
elasticsearch    6.4.2     e47ebd7ec3ee  7 weeks ago  828MB

当前通过邮递员发送请求

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/30459
文章 [ 1 ]  |  最新文章 7 年前
Val
Reply   •   1 楼
Val    7 年前

如果您想要自动创建ID,只需使用 index 而不是 create 以下内容:

change this
    |
    v
{"index": {"_index": "test", "_type": "_doc"} }
{"user": "kimchy", "post_date": "2002-11-15T14:12:12", "message": "trying out Elasticsearch"}