Introduction
Updating documents lets you change information already saved in Elasticsearch without deleting and adding it again.
POST /index_name/_update/document_id
{
"doc": {
"field_name": "new_value"
}
}POST /products/_update/1 { "doc": { "price": 19.99 } }
POST /users/_update/42 { "doc": { "last_login": "2024-06-01T12:00:00" } }
POST /orders/_update/100 { "doc": { "status": "shipped" } }
POST /library/_update/123 { "doc": { "title": "Learn Elasticsearch", "available": true } }
_update API in Elasticsearch do?_update API_update API is designed to change parts of a document without replacing the entire document.status to "active" in a document with ID 1 in index users?/index/_update/document_id.doc object. POST /users/_update/1 { "doc": { "status": "active" } } matches this format exactly.POST /products/_update/42
{
"doc": {
"price": 19.99
}
}_update API updates only the fields inside the doc object, leaving other fields intact.price field is specified, so other fields stay as they were.POST /orders/_update/100
{
"status": "shipped"
}doc object wrapping the fields to update.doc wrapper, causing a syntax error.stock field by 5 in a product document with ID 10. Which update request correctly does this?stock. Others either overwrite or use wrong syntax.Pass the test and this pattern moves unknown