Solr supports simple atomic updates (also called partial updates) to single documents via field modifiers such as add and inc.

Optimistic concurrency control is another method of atomically updating documents.


Solr supports several modifiers that atomically update values of a document.

  • set – set or replace a particular value, or remove the value if null is specified as the new value
  • add – adds an additional value to a list
  • remove – removes a value (or a list of values) from a list
  • inc – increments a numeric value by a specific amount (use a negative value to decrement)

Note: All original source fields must be stored for field modifiers to work correctly.  This is the default in Solr.

Update Modifier Example

First, let’s add a document representing a book:

$ curl http://localhost:8983/solr/update -H 'Content-type:application/json' -d '
 {"id" : "book1", "title" : "Snow Crash",
  "copies_i" : 5, "cat" : "Science Fiction"

Now we can update that document, adding the author field, incrementing the number of copies we have, and adding an additional category:

$ curl http://localhost:8983/solr/update -H 'Content-type:application/json' -d '
 {"id"       : "book1",
  "author"   : {"set":"Neal Stephenson"},
  "copies_i" : {"inc":3},
  "cat"      : {"add":"Cyberpunk"}

Now if we retrieve the document using real-time get, we will see the updated fields:

$ curl http://localhost:8983/solr/get?id=book1
  "doc": {
    "title":["Snow Crash"],
    "cat":["Science Fiction", "Cyberpunk"],
    "author":"Neal Stephenson",


And finally, remove “Cyberpunk” from the cat field:

$ curl http://localhost:8983/solr/update -H 'Content-type:application/json' -d '
 {"id"       : "book1",
  "cat"      : {"remove":"Cyberpunk"}


Atomic Updates with SolrJ

Here is an example of how to do a partial update via Solr’s Java client, SolrJ:

    // create the SolrJ client
    HttpSolrServer client = new HttpSolrServer("http://localhost:8983/solr");

    // create the document
    SolrInputDocument sdoc = new SolrInputDocument();
    Map fieldModifier = new HashMap<>(1);
    sdoc.addField("cat", fieldModifier);  // add the map as the field value

    client.add( sdoc );  // send it to the solr server

    client.shutdown();  // shutdown client before we exit