To update the data, the same syntax is used as an add document. While adding, the ID is not present in the system, if present, the existing data will be updated with the value provided. For example, the following command will update existing students' record having _id equal to five.
With a REST client (Postman), use the following:
- URL: http://localhost:9200/students/student/5
- Method: POST
- Type: JSON (application/json)
- Body:
{
"name":"Robert",
"standard":6,
"division":"C",
"gender":"M"
}
With Kibana, go to the Dev Tools and execute the following query:
PUT students/student/5
{
"name":"Robert",
"standard":6,
"division":"C",
"gender":"M"
}
Inserting and updating operations use similar syntax and if you try to add the record with an ID that already exists, then that record will be updated by mistake. To avoid this, you can use the localhost:9200/students/student/1/_create URL. This will throw an error if a record already exists with a 1 ID. Similarly, you can use localhost:9200/students/student/1/_update in case you wish to update the record. It will throw an error if a record does not exist while updating it.