Partial updates in Elasticsearch - Time & Space Complexity
When we update only part of a document in Elasticsearch, it is important to understand how the time to do this update changes as the document size grows.
We want to know how the update operation's cost grows when documents get bigger or more complex.
Analyze the time complexity of the following partial update request.
POST /my_index/_update/1
{
"doc": {
"field": "new value"
}
}
This code updates only the "field" inside the document with ID 1, without replacing the whole document.
In this partial update, Elasticsearch must:
- Primary operation: Read the existing document from storage.
- How many times: Once per update request.
- Then merge the updated fields into the document.
- Finally, write the updated document back to storage.
The dominant work is reading and rewriting the whole document, even if only part changes.
As the document size (n) grows, the time to read and rewrite it grows roughly in proportion.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 KB document | Small read and write time |
| 100 KB document | About 10 times more work than 10 KB |
| 1 MB document | About 100 times more work than 10 KB |
Pattern observation: The time grows roughly linearly with document size because the whole document must be processed.
Time Complexity: O(n)
This means the update time grows in direct proportion to the size of the document being updated.
[X] Wrong: "Partial updates only change the small part, so update time is constant no matter document size."
[OK] Correct: Even if only a small part changes, Elasticsearch reads and rewrites the entire document, so time depends on document size.
Understanding how partial updates work helps you reason about performance in real systems where documents vary in size.
This skill shows you can think about how data size affects operation cost, a key part of building efficient search solutions.
What if Elasticsearch supported in-place partial updates without rewriting the whole document? How would the time complexity change?