The document was updated while using GET request with JSON content


#1

Hi all,

I was practicing the simple DSL in Kibana dev tools page. (Elasticsearch version: 5.4.1)
There is only one document in the new index.

Create document

PUT /megacorp/employee/1
{
    "first_name" : "John",
    "last_name" :  "Smith",
    "age" :        25,
    "about" :      "I love to go rock climbing",
    "interests": [ "sports", "music" ]
}

Then, I changed PUT to GET, also changed age to 30.

GET /megacorp/employee/1
{
    "first_name" : "John",
    "last_name" :  "Smith",
    "age" :        30,
    "about" :      "I love to go rock climbing",
    "interests": [ "sports", "music" ]
}

I just want to test whether I use the GET request with JSON content or not, then elasticsearch returns these messages:

{
  "_index": "megacorp",
  "_type": "employee",
  "_id": "1",
  "_version": 6,
  "result": "updated",
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "created": false
}

Looks like the document has been updated. The age field is 30 now.

{
  "_index": "megacorp",
  "_type": "employee",
  "_id": "1",
  "_version": 7,
  "found": true,
  "_source": {
    "first_name": "John",
    "last_name": "Smith",
    "age": 30,
    "about": "I love to go rock climbing",
    "interests": [
      "sports",
      "music"
    ]
  }
}

I know I can just use the simple one line to query documents (GET /megacorp/employee/1),
but I'm a little curiosity about why can GET request do the update operation.
Does it work as designed?


(David Pilato) #2

Your GET with body is actually sent as a POST. That's why it's updated.

If you use curl instead you will see that the body is ignored.


#3

Thank you for your helpful explanation!


(system) #4

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