0
0
Elasticsearchquery~5 mins

Partial updates in Elasticsearch - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Partial updates
O(n)
Understanding Time 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.

Scenario Under Consideration

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.

Identify Repeating Operations

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.

How Execution Grows With Input

As the document size (n) grows, the time to read and rewrite it grows roughly in proportion.

Input Size (n)Approx. Operations
10 KB documentSmall read and write time
100 KB documentAbout 10 times more work than 10 KB
1 MB documentAbout 100 times more work than 10 KB

Pattern observation: The time grows roughly linearly with document size because the whole document must be processed.

Final Time Complexity

Time Complexity: O(n)

This means the update time grows in direct proportion to the size of the document being updated.

Common Mistake

[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.

Interview Connect

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.

Self-Check

What if Elasticsearch supported in-place partial updates without rewriting the whole document? How would the time complexity change?