# Why is a version conflict excpetion thrown when no versioning is used or required?

**URL:** <https://discuss.elastic.co/t/why-is-a-version-conflict-excpetion-thrown-when-no-versioning-is-used-or-required/201343>\
**Category:** Elasticsearch\
**Created:** [September 27, 2019, 6:28am UTC](https://discuss.elastic.co/t/why-is-a-version-conflict-excpetion-thrown-when-no-versioning-is-used-or-required/201343 "2019-09-27T06:28:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cawoodm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cawoodm/32/14083_2.png) [@cawoodm](https://discuss.elastic.co/u/cawoodm)\
**Post date:** [September 27, 2019, 6:28am UTC](https://discuss.elastic.co/t/why-is-a-version-conflict-excpetion-thrown-when-no-versioning-is-used-or-required/201343/1 "2019-09-27T06:28:11Z")

</div>

# version\_conflict\_engine\_exception

We're using ElasticSearch as a Cache and when we run a stress test with 10 processes simultaneously accessing and writing to ES we occasionally get a `version_conflict_engine_exception` exception. This is strange since we are not working with versions and do not provide a `_version` field. The last write should just win.

How can we avoid this problem or should we just ignore it?

We are using the NPM Package for ElasticSearch Client.

## Request

```
PUT /mycache/_create/XYZ30034501 HTTP/1.1

{"part":"XYZ-30034-501","timestamp":"2019-09-27T06:23:09.209Z"}

```

## Response

```
HTTP/1.1 409 Conflict
content-type: application/json; charset=UTF-8
content-length: 457

{
  "error": {
    "root_cause": [
      {
        "type": "version_conflict_engine_exception",
        "reason": "[XYZ30034501]: version conflict, document already exists (current version [1])",
        "index_uuid": "UoYuAeWUTiaIhJkYiPs72g",
        "shard": "0",
        "index": "partcache-dev1"
      }
    ],
    "type": "version_conflict_engine_exception",
    "reason": "[XYZ30034501]: version conflict, document already exists (current version [1])",
    "index_uuid": "UoYuAeWUTiaIhJkYiPs72g",
    "shard": "0",
    "index": "partcache-dev1"
  },
  "status": 409
}
```

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [September 27, 2019, 7:14am UTC](https://discuss.elastic.co/t/why-is-a-version-conflict-excpetion-thrown-when-no-versioning-is-used-or-required/201343/2 "2019-09-27T07:14:04Z")

</div>

You are using the `_create` API which returns `409 Conflict` if the document already exists. Under the hood, this works by requiring the document version to be `0`.

---

<div class="post-metadata">

**Author:** ![cawoodm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cawoodm/32/14083_2.png) [@cawoodm](https://discuss.elastic.co/u/cawoodm)\
**Post date:** [September 27, 2019, 7:51am UTC](https://discuss.elastic.co/t/why-is-a-version-conflict-excpetion-thrown-when-no-versioning-is-used-or-required/201343/4 "2019-09-27T07:51:35Z")

</div>

Switching to the client's `index()` [method](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#_index) has solved this issue.

Many thanks David!

---

<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:** [October 25, 2019, 7:51am UTC](https://discuss.elastic.co/t/why-is-a-version-conflict-excpetion-thrown-when-no-versioning-is-used-or-required/201343/5 "2019-10-25T07:51:36Z")

</div>

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