带有多个_update_by_query的version_conflict_engine_exception

时间:2018-03-30 13:28:32

标签: elasticsearch

我遇到了version_conflict_engine_exception的情况。我有守护进程不断推送数据以更新到elasticsearch。我正在使用_updat_by_query。以下是示例电话:

curl -XPOST 'localhost:9200/my_index/my_type/_update_by_query?pretty' -H 'Content-Type: application/json' -d '
{
   "query":{
      "term":{
         "userid":1234
      }
   },
   "script":{
      "lang":"painless",
      "inline":"if (ctx._source.containsKey(\"newfield\")) {ctx._source.newfiled.add(params.value)} else {ctx._source.newfield = [params.value]}",
      "params":{
         "value":{"new":"value"}
      }
   }
}'

每当我有相同的用户ID(在query.terms上)时,会有一个接一个的多个更新查询点击,它会给我一个错误version_conflict_engine_exception。我知道它是因为版本冲突但我们如何克服这个我经常更新查询的地方。我也没有找到bulk的任何_update_by_query选项。我收到了以下错误:

{
    "took": 1,
    "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.0,
    "throttled_until_millis": 0,
    "failures": [{
        "index": "my_index",
        "type": "my_type",
        "id": "Gc-_SWIBUzg1_4kxJ5uD",
        "cause": {
            "type": "version_conflict_engine_exception",
            "reason": "[logs][Gc-_SWIBUzg1_4kxJ5uD]: version conflict, current version [2] is different than the one provided [1]",
            "index_uuid": "dbtt5uS9R3ClcPt6Oar1MQ",
            "shard": "3",
            "index": "my_index"
        },
        "status": 409
    }]
}

1 个答案:

答案 0 :(得分:0)

目前这是Elasticsearch中的预期行为。您可以尝试使用冲突和刷新参数来解决此问题。

您可以使用

curl -XPOST 'localhost:9200/my_index/my_type/_update_by_query?conflicts=proceed&refresh=wait_for

如此处所述。希望有所帮助!