[Performance] Which is better update via script or storing the complete object?


(Abhishek Gupta) #1

There are two options to update an object in ES:

  1. using update APIs (via script)
  2. storing the complete object again with the id set

There are many scenarios when choosing among these two options is easy like:

  1. When you want to do conditional updates script is the winner.
  2. In case you in the application logic only have the update part not the complete object than again script is the clear winner.

But I have a situation where I have the complete object in my hand. Out of the complete object I only want to update a very small part. So what should I use, storing the complete object or updating it via script. Which will perform better?


(Nik Everett) #2

They'll perform mostly the same.The real overhead of an update is indexing the new document and cleaning up the tombstone of the old document on the next time its merged. The tombstones also cost IO during queries and effect the scoring so if you get too many that is trouble eventually.

The way in which the update hits the system isn't a huge part of it. My biggest bit of advice is to avoid noop updates. If you send the whole object there is a flag you can turn on to detect noops but if you send a script then the responsibility is on you.

Oh! If you go the script route make sure its parameterized or else compiling it will be overhead. If its parameterized then it is only compiled once.


(system) #3