# Version conflict always on \_delete\_from\_query

**URL:** <https://discuss.elastic.co/t/version-conflict-always-on-delete-from-query/137145>\
**Category:** Elasticsearch\
**Created:** [June 24, 2018, 12:38pm UTC](https://discuss.elastic.co/t/version-conflict-always-on-delete-from-query/137145 "2018-06-24T12:38:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mackrispi](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@mackrispi](https://discuss.elastic.co/u/mackrispi)\
**Post date:** [June 24, 2018, 12:38pm UTC](https://discuss.elastic.co/t/version-conflict-always-on-delete-from-query/137145/1 "2018-06-24T12:38:15Z")

</div>

Hi,

I have a simple index. When I add document, this document has a version of 1 as shown below.

If I then call \_delete\_for\_update .... I always get version conflict and I don't know why. If I re-run the delete script then it is deleted as expected ...

There was no other insert nor update .... I call php script for insert and delete manually ....

Here is my example :

```
    {
            "_index" : "i8grpusr1",
            "_type" : "grpusr",
            "_id" : "70437463654587_447",
            "_version" : 1,
            "_score" : 1.0,
            "_source" : {
              "fk_groups" : "447",
              "fullname" : "",
              "gid_users" : "70437463654587"
            }
          },
          {
            "_index" : "i8grpusr1",
            "_type" : "grpusr",
            "_id" : "70437463654587_361",
            "_version" : 1,
            "_score" : 1.0,
            "_source" : {
              "fk_groups" : "361",
              "fullname" : "",
              "gid_users" : "70437463654587"
            }
          },
          {
            "_index" : "i8grpusr1",
            "_type" : "grpusr",
            "_id" : "70437463654587_449",
            "_version" : 1,
            "_score" : 1.0,
            "_source" : {
              "fk_groups" : "449",
              "fullname" : "",
              "gid_users" : "70437463654587"
            }
          }

```

After I all \_delete\_for\_update I get this :

```
{
	"took": 3,
	"timed_out": false,
	"total": 3,
	"deleted": 1,
	"batches": 1,
	"version_conflicts": 2,
	"noops": 0,
	"retries": {
		"bulk": 0,
		"search": 0
	},
	"throttled_millis": 0,
	"requests_per_second": -1.0,
	"throttled_until_millis": 0,
	"failures": [{
		"index": "i8grpusr1",
		"type": "grpusr",
		"id": "70437463654587_447",
		"cause": {
			"type": "version_conflict_engine_exception",
			"reason": "[grpusr][70437463654587_447]: version conflict, current version [2] is different than the one provided [1]",
			"index_uuid": "kZXuIQAiSEy7HbdDs6KHXg",
			"shard": "0",
			"index": "i8grpusr1"
		},
		"status": 409
	}, {
		"index": "i8grpusr1",
		"type": "grpusr",
		"id": "70437463654587_449",
		"cause": {
			"type": "version_conflict_engine_exception",
			"reason": "[grpusr][70437463654587_449]: version conflict, current version [2] is different than the one provided [1]",
			"index_uuid": "kZXuIQAiSEy7HbdDs6KHXg",
			"shard": "0",
			"index": "i8grpusr1"
		},
		"status": 409
	}]
}

```

And I call \_delete\_by\_query like this :

```
{
	"query": {
		"term": {
			"fk_groups": ' . $id . '
		}
	}
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 24, 2018, 1:26pm UTC](https://discuss.elastic.co/t/version-conflict-always-on-delete-from-query/137145/2 "2018-06-24T13:26:40Z")

</div>

May be you are updating some documents while trying to remove them?

You can use `?conflicts=proceed` If you don't want to abort but just count the conflicted documents.

---

<div class="post-metadata">

**Author:** ![mackrispi](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@mackrispi](https://discuss.elastic.co/u/mackrispi)\
**Post date:** [June 25, 2018, 9:54am UTC](https://discuss.elastic.co/t/version-conflict-always-on-delete-from-query/137145/3 "2018-06-25T09:54:36Z")

</div>

Hi,  
I do bulk insert and the result is what I've showed above.  
Then I do delete by query .... that's it.

Counting is not ok, cause I need to make sure all documents are deleted .....

I do insert with PUT  
xxxx/grpusr/70437463654587\_447?refresh&filter\_path=created,result&pretty

Thank you

---

<div class="post-metadata">

**Author:** ![mackrispi](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@mackrispi](https://discuss.elastic.co/u/mackrispi)\
**Post date:** [June 25, 2018, 10:45am UTC](https://discuss.elastic.co/t/version-conflict-always-on-delete-from-query/137145/4 "2018-06-25T10:45:02Z")

</div>

Hi,

I might have found the problem ....  
I have users and groups .... user owns some groups ... and can be part of some other group

If I delete user... then I first go end delete groups he owns .... and I call \_delete\_by\_query ... where query is by group ID ....

Then go and delete user ... and I again call \_delete\_by\_query on the same index as before but on user ID ...

So is it possible that \_delete\_by\_query increments version until it is deleted ?  
I don't call REFRESH when deleting .... as I do when I ADD ...

And for some reason first delete didn't finish processing in ES, and cause I call it again then the version conflict appears ?

* * *

## Update:

I added REFRESH while calling \_Delete\_for\_update and it looks ok now, without conflicts ....

Question: Will adding refresh cause performance issues when there will be a few million rows ?  
If yes, should we build a logic without calling refresh ? OK this would mean that user will see results after some time ... but how much time is this ? A few minutes is ok , hours is not ...  
Of course we don't expect \_delete\_for\_query to be called 100 times a second, but every 30sec it might ...  
Thank you.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 25, 2018, 12:45pm UTC](https://discuss.elastic.co/t/version-conflict-always-on-delete-from-query/137145/5 "2018-06-25T12:45:56Z")

</div>

Yes. Deleting a document does increase the version. It's like an update which is marking a document to be removed eventually.

If you run both scripts at the same time, that might explain.

---

<div class="post-metadata">

**Author:** ![mackrispi](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@mackrispi](https://discuss.elastic.co/u/mackrispi)\
**Post date:** [June 25, 2018, 1:02pm UTC](https://discuss.elastic.co/t/version-conflict-always-on-delete-from-query/137145/6 "2018-06-25T13:02:33Z")

</div>

Can you please say something regarding performance that I wrote ?  
thank you.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 29, 2018, 9:47pm UTC](https://discuss.elastic.co/t/version-conflict-always-on-delete-from-query/137145/7 "2018-06-29T21:47:21Z")

</div>

Calling refresh will cause indeed performance problems IMO.

---

<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 27, 2018, 9:47pm UTC](https://discuss.elastic.co/t/version-conflict-always-on-delete-from-query/137145/8 "2018-07-27T21:47:29Z")

</div>

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