# Delete by query and date range causes unexpected "version\_conflict\_engine\_exception", 409 response

**URL:** <https://discuss.elastic.co/t/delete-by-query-and-date-range-causes-unexpected-version-conflict-engine-exception-409-response/308227>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [June 27, 2022, 9:49am UTC](https://discuss.elastic.co/t/delete-by-query-and-date-range-causes-unexpected-version-conflict-engine-exception-409-response/308227 "2022-06-27T09:49:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bizmate](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bizmate/32/24977_2.png) [@bizmate](https://discuss.elastic.co/u/bizmate)\
**Post date:** [June 27, 2022, 9:49am UTC](https://discuss.elastic.co/t/delete-by-query-and-date-range-causes-unexpected-version-conflict-engine-exception-409-response/308227/1 "2022-06-27T09:49:22Z")

</div>

I am running a query to delete certain logs/entries before a certain date with a log level of "Debug" as shown here, notice the wildcard in the index name

```auto
POST /my_index_prod*/_delete_by_query
{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "timestamp": {
                "lte": "now-30d/d"
            }
          }
        }
      ],
      "filter": [
        {
          "match_all": {}
        },
        {
          "match_phrase": {
            "level": "DEBUG"
          }
        }
      ],
      "should": [],
      "must_not": []
    }
  }
}

```

But i keep seeing that a lot of logs are catched by this condition but only a few deleted and the errors return include a lot of `version_conflict_engine_exception`

Example

```auto
{
  "took" : 39228,
  "timed_out" : false,
  "total" : 4594818,
  "deleted" : 2354,
  "batches" : 3,
  "version_conflicts" : 646,
  "noops" : 0,
  "retries" : {
    "bulk" : 0,
    "search" : 0
  },
  "throttled_millis" : 0,
  "requests_per_second" : -1.0,
  "throttled_until_millis" : 0,
  "failures" : [
    {
      "index" : "my_index_prod-filebeat-7.14.0-2022.05",
      "type" : "_doc",
      "id" : "lRZHBoEBMAL2EtIf6Pbg",
      "cause" : {
        "type" : "version_conflict_engine_exception",
        "reason" : "[lRZHBoEBMAL2EtIf6Pbg]: version conflict, required seqNo [2369859], primary term [1]. but no document was found",
        "index_uuid" : "gAa8nhj6Q2mt4mXnC_u9-w",
        "shard" : "0",
        "index" : "my_index_prod-filebeat-7.14.0-2022.05"
      },
      "status" : 409
    },
    {
      "index" : "my_index_prod-filebeat-7.14.0-2022.05",
      "type" : "_doc",
      "id" : "qBZHBoEBMAL2EtIf6Pbg",
      "cause" : {
        "type" : "version_conflict_engine_exception",
        "reason" : "[qBZHBoEBMAL2EtIf6Pbg]: version conflict, required seqNo [2369865], primary term [1]. but no document was found",
        "index_uuid" : "gAa8nhj6Q2mt4mXnC_u9-w",
        "shard" : "0",
        "index" : "my_index_prod-filebeat-7.14.0-2022.05"
      },
      "status" : 409
    },

...
  ]
}

```

What am I doing wrong and what can I do to fix this?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 25, 2022, 9:50am UTC](https://discuss.elastic.co/t/delete-by-query-and-date-range-causes-unexpected-version-conflict-engine-exception-409-response/308227/2 "2022-07-25T09:50:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
