UPDATEs/GETs against same index and document/id guaranteed?

Hi, after a lot of reading I am still not 100% clear about the following two questions:

  • is the order of "update" requests (against the same index and document/id) guaranteed?

  • is the order between updates/gets requests (against the same index and document/id) guaranteed?

Reduced example:

(assuming all of these are on the same index and same document/id)

  • Create docA
    {
    keyA: '',
    keyB: ''
    }

  • Update docA (change 'keyA' to '1')

  • Update docA (change 'keyB' to '2')

  • Update docA (change 'keyA' to '3')

  • GET docA
    I would expect to receive the following:
    {
    keyA: '2',
    keyB: '3'
    }

  • Update docA (change 'keyA' to '4')

  • GET docA
    I would expect to receive the following:
    {
    keyA: '4',
    keyB: '3'
    }

Thanks!

is the order of "update" requests (against the same index and document/id) guaranteed?

Yes if requests are sent one after the other (after the response from elasticsearch). No if they are sent in parallel (without waiting for elasticsearch response) even though one after the other.

So if you run this in Kibana (I think there was some typos in your example):

DELETE test
PUT test
PUT test/_doc/docA
{
  "keyA": "",
  "keyB": ""
}
PUT test/_doc/docA
{
  "keyA": "1",
  "keyB": ""
}
PUT test/_doc/docA
{
  "keyA": "1",
  "keyB": "2"
}
PUT test/_doc/docA
{
  "keyA": "3",
  "keyB": "2"
}
GET test/_doc/docA
PUT test/_doc/docA
{
  "keyA": "4",
  "keyB": "2"
}
GET test/_doc/docA

You will always get back:

# DELETE test
{
  "acknowledged" : true
}


# PUT test
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "test"
}


# PUT test/_doc/docA
{
  "_index" : "test",
  "_type" : "_doc",
  "_id" : "docA",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}


# PUT test/_doc/docA
{
  "_index" : "test",
  "_type" : "_doc",
  "_id" : "docA",
  "_version" : 2,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 1,
  "_primary_term" : 1
}


# PUT test/_doc/docA
{
  "_index" : "test",
  "_type" : "_doc",
  "_id" : "docA",
  "_version" : 3,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 2,
  "_primary_term" : 1
}


# PUT test/_doc/docA
{
  "_index" : "test",
  "_type" : "_doc",
  "_id" : "docA",
  "_version" : 4,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 3,
  "_primary_term" : 1
}


# GET test/_doc/docA
{
  "_index" : "test",
  "_type" : "_doc",
  "_id" : "docA",
  "_version" : 4,
  "_seq_no" : 3,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "keyA" : "3",
    "keyB" : "2"
  }
}


# PUT test/_doc/docA
{
  "_index" : "test",
  "_type" : "_doc",
  "_id" : "docA",
  "_version" : 5,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 4,
  "_primary_term" : 1
}


# GET test/_doc/docA
{
  "_index" : "test",
  "_type" : "_doc",
  "_id" : "docA",
  "_version" : 5,
  "_seq_no" : 4,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "keyA" : "4",
    "keyB" : "2"
  }
}
2 Likes

Thanks for the clear answer, really appreciate it. :+1:

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