# Update Where or Locking with ElasticSearch?

**URL:** <https://discuss.elastic.co/t/update-where-or-locking-with-elasticsearch/9834>\
**Category:** Elasticsearch\
**Created:** [November 27, 2012, 5:49am UTC](https://discuss.elastic.co/t/update-where-or-locking-with-elasticsearch/9834 "2012-11-27T05:49:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbrianjones](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbrianjones/32/1402_2.png) [@tbrianjones](https://discuss.elastic.co/u/tbrianjones)\
**Post date:** [November 27, 2012, 5:49am UTC](https://discuss.elastic.co/t/update-where-or-locking-with-elasticsearch/9834/1 "2012-11-27T05:49:36Z")

</div>

I have a document property in an ElasticSearch index called 'processing.'  
It's a boolean value that records whether or not an external program is  
running that is working with that document. I am running many external  
processors, but documents cannot be processed by multiple programs at once.

Am I able to select a document that is not being processed and update the  
'processing' property to TRUE without another processor sneaking in and  
choosing the document? Is there an UPDATE WHERE type operation I can  
perform that will return the \_id of the document that was updated?

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [November 27, 2012, 8:32am UTC](https://discuss.elastic.co/t/update-where-or-locking-with-elasticsearch/9834/2 "2012-11-27T08:32:48Z")

</div>

On Mon, 2012-11-26 at 21:49 -0800, Brian Jones wrote:

> I have a document property in an Elasticsearch index called  
> 'processing.' It's a boolean value that records whether or not an  
> external program is running that is working with that document. I am  
> running many external processors, but documents cannot be processed by  
> multiple programs at once.
> 
> Am I able to select a document that is not being processed and update  
> the 'processing' property to TRUE without another processor sneaking  
> in and choosing the document? Is there an UPDATE WHERE type operation  
> I can perform that will return the \_id of the document that was  
> updated?

Yes you can - use the update api, pass the current version number and  
leave retry\_on\_conflict set to zero:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

alternatively, you could just use the create and delete APIs. If you try  
to create a document with a particular ID and it fails, then something  
else has already created it. Once the job is done, delete the document.

clint

--

---

<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, 3:02am UTC](https://discuss.elastic.co/t/update-where-or-locking-with-elasticsearch/9834/3 "2017-07-06T03:02:51Z")

</div>


