Elasticsearch document locking concept

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

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

response is

{
  "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

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

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

Thank You

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.

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

Thanks.

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


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

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 is just a way to implement locking in Elasticsearch, but in the end you are just creating and deleting a bunch of documents.

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