What if you could fix just one tiny detail without rewriting the whole story?
Why Partial updates in Elasticsearch? - Purpose & Use Cases
Imagine you have a huge document stored in Elasticsearch, like a detailed user profile with many fields. Now, you want to change just the user's phone number. Without partial updates, you'd have to fetch the entire document, change the phone number manually, and then send the whole document back to Elasticsearch.
This manual way is slow because you transfer and rewrite the entire document even if only one small part changes. It's also risky because you might accidentally overwrite other fields or lose data if you miss something. Plus, it wastes bandwidth and processing power.
Partial updates let you send only the changes you want to make. Elasticsearch applies these changes directly to the stored document without needing the full data. This makes updates faster, safer, and more efficient.
GET /index/_doc/1 // fetch full document PUT /index/_doc/1 { "name": "Alice", "phone": "12345", "email": "alice@example.com" }
POST /index/_update/1 { "doc": { "phone": "12345" } }
Partial updates enable quick, precise changes to documents without the overhead of resending or risking full document replacement.
In a social media app, when a user changes their profile picture, partial updates let you update just the picture URL without touching the rest of their profile data.
Manual full-document updates are slow and risky.
Partial updates send only the changed fields.
This makes updates faster, safer, and more efficient.
Practice
Solution
Step 1: Understand partial update concept
Partial updates allow changing only some fields of a document instead of replacing the entire document.Step 2: Identify the main purpose
This saves bandwidth and time by sending only the changed fields, not the whole document.Final Answer:
To update only specific fields of a document without replacing the whole document -> Option CQuick Check:
Partial update = update some fields only [OK]
- Confusing partial update with document deletion
- Thinking partial update creates new documents
- Believing partial update retrieves documents
Solution
Step 1: Identify correct HTTP method and endpoint
Partial updates use POST method on the _update API with the document ID.Step 2: Check request body format
The update body must include a "doc" key with the fields to update.Final Answer:
POST /products/_update/1 { "doc": { "price": 20 } } -> Option BQuick Check:
Use POST + _update + doc key [OK]
- Using GET instead of POST for update
- Omitting the 'doc' key in request body
- Using PUT on _update endpoint incorrectly
- Updating with _doc endpoint instead of _update
POST /users/_update/2
{
"doc": {
"age": 30
}
}If the original document was {"name": "Alice", "age": 25}, what will be the document after the update?
Solution
Step 1: Understand partial update effect
The partial update changes only the "age" field to 30, keeping other fields unchanged.Step 2: Apply update to original document
Original document {"name": "Alice", "age": 25} becomes {"name": "Alice", "age": 30} after update.Final Answer:
{"name": "Alice", "age": 30} -> Option AQuick Check:
Partial update changes only specified fields [OK]
- Thinking update replaces whole document
- Assuming fields not in doc are removed
- Adding extra fields not in update request
POST /orders/_update/5
{
"doc": {
"status": "shipped"
}
}But you get an error. Which is the most likely cause?
Solution
Step 1: Check common update errors
Partial update errors often happen if the document ID does not exist.Step 2: Analyze given request and error cause
The syntax is correct, so the likely cause is missing document with ID '5'.Final Answer:
The document with ID '5' does not exist in 'orders' index -> Option AQuick Check:
Missing document ID causes update error [OK]
- Confusing HTTP method errors with missing document
- Assuming all fields are immutable
- Omitting 'doc' key causing syntax errors
Solution
Step 1: Understand increment operation in partial update
To increase a numeric field, use a script that adds the value to the existing field.Step 2: Identify correct syntax for scripted update
{ "script": { "source": "ctx._source.stock += params.count", "params": { "count": 10 } } } uses the 'script' key with source code to add 10 to 'stock'.Final Answer:
{ "script": { "source": "ctx._source.stock += params.count", "params": { "count": 10 } } } -> Option DQuick Check:
Use script to increment numeric fields [OK]
- Trying to update with doc key using expression string
- Using 'update' key instead of 'doc' or 'script'
- Assigning value directly instead of incrementing
Ready to prove it?
Pass the test and this pattern moves unknown
