# Strange DocumentAlreadyExists / VersionConflictError exceptions

**URL:** <https://discuss.elastic.co/t/strange-documentalreadyexists-versionconflicterror-exceptions/25252>\
**Category:** Elasticsearch\
**Created:** [July 9, 2015, 4:27pm UTC](https://discuss.elastic.co/t/strange-documentalreadyexists-versionconflicterror-exceptions/25252 "2015-07-09T16:27:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Wolfson](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@Ben\_Wolfson](https://discuss.elastic.co/u/Ben_Wolfson)\
**Post date:** [July 9, 2015, 4:27pm UTC](https://discuss.elastic.co/t/strange-documentalreadyexists-versionconflicterror-exceptions/25252/1 "2015-07-09T16:27:53Z")

</div>

I'm getting some errors I don't really understand (unfortunately only in production, too, I can't reproduce them elsewhere)---occasionally attempts to update or insert a document will result in either a DocumentAlreadyExistsException, or a version conflict (even though I'm not setting a version explicitly).

The code I'm using to insert/update documents (using the Python api) is:

```
self.es.update(index=self.index_name,
               doc_type=obj._doctype,
               id=obj._doc_id,
               body={'doc': obj.to_es(), 'doc_as_upsert': True})

```

Where `self` and `obj` are instances of some helper classes.

Given the `doc_as_upsert` setting I would have thought that if the document already exists it would just be replaced (and this is what happens in the vast majority of cases), not cause an error; given that I'm not setting a version explicitly, the version conflict error seems equally inexplicable. Can anyone help me out? What's going on? Thanks!

---

<div class="post-metadata">

**Author:** ![Ben\_Wolfson](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@Ben\_Wolfson](https://discuss.elastic.co/u/Ben_Wolfson)\
**Post date:** [September 15, 2015, 10:23pm UTC](https://discuss.elastic.co/t/strange-documentalreadyexists-versionconflicterror-exceptions/25252/2 "2015-09-15T22:23:07Z")

</div>

this continues to happen occasionally, and continues to be kind of baffling to me. Why should there be an exception for the document already existing when I explicitly say I want upsert-like behavior?

---

<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 5, 2017, 11:50pm UTC](https://discuss.elastic.co/t/strange-documentalreadyexists-versionconflicterror-exceptions/25252/3 "2017-07-05T23:50:12Z")

</div>


