【问题标题】:Attempting to use Elasticsearch Bulk API when _id is equal to a specific field当 _id 等于特定字段时尝试使用 Elasticsearch Bulk API
【发布时间】:2019-10-09 19:39:12
【问题描述】:

我正在尝试将文档批量插入到索引中。我需要让 _id 等于我要插入的特定字段。我正在使用 ES v6.6

POST productv9/_bulk
{ "index" : { "_index" : "productv9", "_id": "in_stock"}}
{ "description" : "test", "in_stock" : "2001"}

GET productv9/_search
{
  "query": {
    "match": {
      "_id": "2001"
    }
  }
}

当我运行批量语句时,它运行时没有任何错误。但是,当我运行搜索语句时,它没有得到任何点击。此外,我还有许多其他文档想以相同的方式插入。

【问题讨论】:

  • 您有文件中的文档或其他内容作为来源?
  • 唯一的文档是 { "description" : "test", "in_stock" : "2001"} 并且 in_stock 是 _source 中的一个字段

标签: elasticsearch elasticsearch-painless


【解决方案1】:

我建议做的是创建一个ingest pipeline,它将根据in_stock 字段的值设置文档的_id

首先创建管道:

PUT _ingest/pipeline/set_id
{
  "description" : "Sets the id of the document based on a field value",
  "processors" : [
    {
      "set" : {
        "field": "_id",
        "value": "{{in_stock}}"
      }
    }
  ]
}

然后您可以在批量调用中引用管道:

POST productv9/doc/_bulk?pipeline=set_id
{ "index" : {}}
{ "description" : "test", "in_stock" : "2001"}

致电GET productv9/_doc/2001,您将获得您的文件。

【讨论】:

  • 没有类型的 _bulk 如何在 ES 6.6 上工作?不应该是POST productv9/_doc/_bulk吗?
  • 是的,我在 ES7 上测试过...现在已修复。
  • 太棒了,很高兴它有帮助!
猜你喜欢
  • 2014-08-27
  • 2017-12-31
  • 1970-01-01
  • 2020-01-05
  • 1970-01-01
  • 1970-01-01
  • 2015-11-06
  • 2019-09-22
  • 1970-01-01
相关资源
最近更新 更多