# Indexing new document and check version

**URL:** <https://discuss.elastic.co/t/indexing-new-document-and-check-version/23387>\
**Category:** Elasticsearch\
**Created:** [April 24, 2015, 6:52am UTC](https://discuss.elastic.co/t/indexing-new-document-and-check-version/23387 "2015-04-24T06:52:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Jurak](https://avatars.discourse-cdn.com/v4/letter/t/5e9695/32.png) [@Tomas\_Jurak](https://discuss.elastic.co/u/Tomas_Jurak)\
**Post date:** [April 24, 2015, 6:52am UTC](https://discuss.elastic.co/t/indexing-new-document-and-check-version/23387/1 "2015-04-24T06:52:41Z")

</div>

Hi,  
when I create new document and call prepareIndex it overwrites an existing  
one (was created just a nanosecond before this using another thread). Is it  
possible to use ES versions to control this behavior like when doing  
updates?

Problem is, that when document exists I can receive its version prior to  
update and check if I'm updating correct version of document - this is  
working. But when document is not in ES - so get will return null and  
version as -1, and this is returned to more threads simultaneously they all  
call prepareIndex but of coure only last document is saved. I cant pass -1  
as version number into prepareIndex method, it just thow Exception from ES.

Is there any way to check versions on indexing new documents?

Thanks in advance

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e651b694-ba6d-4a16-9c26-7d16008f164c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e651b694-ba6d-4a16-9c26-7d16008f164c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:17am UTC](https://discuss.elastic.co/t/indexing-new-document-and-check-version/23387/2 "2017-07-06T00:17:57Z")

</div>


