skynyrd
3/7/2017 - 7:42 PM

Updating a document

Updating a document

  • PUT deletes existing doc, and replaces with the new one.

Let's create a doc:

PUT /ex_index/ex_type/3
{
  "name" : "EA",
  "goal" : "Knowledge"
}

Updating with PUT:

  PUT /ex_index/ex_type/3
  {
    "name" : "UpdatedName"
  }

Now GET it by GET /ex_index/ex_type/3, goal field is deleted as PUT replaces docs:

{
  "index": "ex_index"
  "type": "ex_type"
  "_id": "3"
  "_version": 2,
  "found" : true,
  "_source" : {
    "name": "UpdatedName"
  }
}

Partial updating with POST:

  POST /ex_index/ex_type/3/_update
  {
    doc: {
      "name" : "UpdatedName"
    }
  }

Updated doc:

{
  "index": "ex_index"
  "type": "ex_type"
  "_id": "3"
  "_version": 2,
  "found" : true,
  "_source" : {
    "name": "UpdatedName",
    "goal" : "Knowledge"
  }
}