# Elasticsearch document locking concept

**URL:** <https://discuss.elastic.co/t/elasticsearch-document-locking-concept/95924>\
**Category:** Elasticsearch\
**Created:** [August 4, 2017, 4:41pm UTC](https://discuss.elastic.co/t/elasticsearch-document-locking-concept/95924 "2017-08-04T16:41:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kabali12345](https://avatars.discourse-cdn.com/v4/letter/k/6a8cbe/32.png) [@kabali12345](https://discuss.elastic.co/u/kabali12345)\
**Post date:** [August 4, 2017, 4:41pm UTC](https://discuss.elastic.co/t/elasticsearch-document-locking-concept/95924/1 "2017-08-04T16:41:00Z")

</div>

Hi,  
This is how i creates lock for particular document with the help of \_id

```auto
PUT logstash-titanic123/lock
{ "create": { "_id": 879},
{ "process_id": 321 } }

```

response is

```auto
{
  "took": 573,
  "errors": false,
  "items": [
    {
      "create": {
        "_index": "titanic_template",
        "_type": "lock",
        "_id": "879",
        "_version": 1,
        "result": "created",
        "_shards": {
          "total": 2,
          "successful": 2,
          "failed": 0
        },
        "created": true,
        "status": 201
      }
    }
  ]
}

```

but when i run below command that locked document getting updated without the help of process\_id

```auto
POST logstash-titanic123/logs/879/_update
{
   "script" : "ctx._source.Pclass = 2 "
}

```

So how can i check whether lock is working or not ?

Thank You

---

<div class="post-metadata">

**Author:** ![s1monw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/s1monw/32/3637_2.png) [@s1monw](https://discuss.elastic.co/u/s1monw)\
**Post date:** [August 11, 2017, 9:17am UTC](https://discuss.elastic.co/t/elasticsearch-document-locking-concept/95924/2 "2017-08-11T09:17:15Z")

</div>

I am not sure I can follow you. What do you mean by a lock. We don't have a concept of a lock in elasticsearch.

---

<div class="post-metadata">

**Author:** ![dangal](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dangal](https://discuss.elastic.co/u/dangal)\
**Post date:** [August 14, 2017, 7:50am UTC](https://discuss.elastic.co/t/elasticsearch-document-locking-concept/95924/3 "2017-08-14T07:50:32Z")

</div>

please go through the below link so that you can understand what am i trying to accomplish...

[https://www.elastic.co/guide/en/elasticsearch/guide/current/concurrency-solutions.html#document-locking](https://www.elastic.co/guide/en/elasticsearch/guide/current/concurrency-solutions.html#document-locking)

Thanks.

---

<div class="post-metadata">

**Author:** ![praveen.b](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@praveen.b](https://discuss.elastic.co/u/praveen.b)\
**Post date:** [September 4, 2017, 1:57pm UTC](https://discuss.elastic.co/t/elasticsearch-document-locking-concept/95924/4 "2017-09-04T13:57:25Z")

</div>

Hi Kabali,

I am trying to create the lock on the document, but the same snippet which you gave, gives error as below.  
Could you let me know if there is any process which should be done before creating the lock.

I have created the index writer/type/lock

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/2/22d46dc1c24b895d8c591d6c7c3296bb0eb82fcb.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/a/ca93a33c332f8f0112e1ae8a4f1c52cb78b6ff9d.png)

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [September 7, 2017, 9:43pm UTC](https://discuss.elastic.co/t/elasticsearch-document-locking-concept/95924/5 "2017-09-07T21:43:53Z")

</div>

> [@praveen.b](#):
>
> I am trying to create the lock on the document, but the same snippet which you gave, gives error as below.
> 
> Could you let me know if there is any process which should be done before creating the lock.

It's because that it is a wrong syntax, it's not following what's described in the docs. The correct syntax should be:

```http
PUT /_bulk
{ "create": { "_id": 879, "_index": "<index_is_required>", "_type": "<type_is_required>" } }
{ "process_id": 321 }

```

Also, if you are to create just a single document, there is no need to use the bulk api.

Lastly, keep in mind that this is not a lock. You are just creating documents in elasticsearch. What is described here [Solving Concurrency Issues | Elasticsearch: The Definitive Guide [2.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/concurrency-solutions.html#document-locking) is just a way to implement locking in Elasticsearch, but in the end you are just creating and deleting a bunch of documents.

---

<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 5, 2017, 9:44pm UTC](https://discuss.elastic.co/t/elasticsearch-document-locking-concept/95924/6 "2017-10-05T21:44:15Z")

</div>

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