在失败时使用 update_by_query 摄取管道会导致 version_conflict_engine_exception

时间:2021-03-24 13:24:24

标签: elasticsearch

情况: 我将“on_failure”语句设置为现有管道,如下所示(对于整个管道):

"on_failure" : [
  {
    "set" : {
      "field" : "_index",
      "value" : "failed-{{ _index }}"
    }
  },
  {
    "set" : {
      "field" : "caused_by",
      "value" : "{{ _ingest.on_failure_message }}"
    }
  }
]

问题: 管道与 update_by_query API 一起使用以丰富文档。在失败的情况下,管道不会将失败的文档转发到失败的索引,即。失败-my_index。这是由于以下错误消息造成的:

{
  "took": 276,
  "timed_out": false,
  "total": 1,
  "updated": 0,
  "deleted": 0,
  "batches": 1,
  "version_conflicts": 1,
  "noops": 0,
  "retries": {
    "bulk": 0,
    "search": 0
  },
  "throttled_millis": 0,
  "requests_per_second": -1,
  "throttled_until_millis": 0,
  "failures": [
    {
      "index": "failed-my_index",
      "type": "_doc",
      "id": "1002109",
      "cause": {
        "type": "version_conflict_engine_exception",
        "reason": "[1002109]: version conflict, required seqNo [37265539], primary term [20]. but no document was found",
        "index_uuid": "JMepgCegQamU8WDqQuFJ3Q",
        "shard": "0",
        "index": "failed-my_index"
      },
      "status": 409
    }
  ]
}

这是真的,因为失败的索引中不存在文档“1002109”,因为它最初索引时并没有失败。 更新时,管道失败,文档需要进入失败的索引。由于上述版本冲突错误,这不会发生。

我在这里做错了什么?

感谢任何帮助

1 个答案:

答案 0 :(得分:1)

如关于 _update_by_query 端点的 official documentation 所述:

<块引用>

此 API 只能让您修改匹配文档的来源,您不能移动它们。

脚本文档中也提供了有关 the update by query context 中可以做什么的信息,因为我们可以看到大多数 ctx._* 字段是只读的:

<块引用>
  • ctx['_routing'](字符串,只读):用于选择文件存储分片的值。
  • ctx['_index'](字符串,只读):索引的名称。
  • ctx['_type'](字符串,只读):索引中的文档类型。
  • ctx['_id'] (int, 只读):唯一的文档 ID。
  • ctx['_version'] (int, 只读):当前版本 文档。

因此,不可能使用按查询更新来更改文档的索引。但是,您可以标记文档,然后使用重新索引 + 按查询删除的组合将这些标记的文档移动到失败的索引中。

相关问题