It will target the indexed document with id=1 and
- it removes the wrong value (“Ralph Jonson”)
- it adds the correct value for the author (“Ralph Johnson”)
- it adds the other missing author
As you can see, the value of a field that needs to be updated is no longer a literal value (e.g. a String, an Integer) or a list of values; instead we have a map where keys are the update commands we want to apply (e.g. remove, add, set) and values are one or more literal values we want to use for the update.
More information about the whole semantic of the AtomicUpdates can be found in the Apache Solr Reference Guide[2]: here it is important to remember that Solr side, there’s no a “true” partial update happening behind the scenes: the old version of the document is fetched and it is merged with the partial state; after that, the new “full” resulting document is indexed again.
Still it is hugely beneficial as it reduced a lot the amount of data you may transfer to Solr when you need to update documents.
In Java, specifically in SolrJ, the SolrInputDocument class represents data we send to Solr for indexing. That is basically a Map so we can add, set or remove fields and values.
We are interested in the following three methods: