How do I ensure an index is the first for a document?

In a concurrent system, I believe I understand optimistic locking and passing the version query string parameter along. However, that is only if the document exists. I.e. you can't send ?version=0. What is the equivalent of optimistic locking for the initial indexing of a document?

Thanks,
John

You can send a create document request. This will fail if it already exists.

1 Like

Hi Christian,

If I'm reading the documentation correctly that is only when not specifying an id. Which in our system we have our own ids. It that how you understand how createdocument works as well?

-John

If you send without an ID the document should always get created as no collisions can occur. This is for then you do specify an external ID. The following should show this:

# Create initial version
POST /test/_create/1
{
  "VERSION": 1
}

# Should fail
POST /test/_create/1
{
  "VERSION": 2
}

# Here we specify type and this should work
POST /test/_doc/1
{
  "VERSION": 2
}

Oh, nice. This helped.

One thing, the notation I used was slightly different.

POST /test/doc/1/_create

Thanks for the help!

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