Reputation: 19
I'm using Solr6.2 and wanna update specific field in a document somewhat like that in relational db: update table_a set field_x = filed_x+1;
How to acheive that in Solr? Thanks in advance.
Upvotes: 1
Views: 1380
Reputation: 52822
For this to work you'll need to have all fields set as stored, since you can then use Solr's support for Updating Parts of Documents.
You can then use the inc
command to increment a field in a document:
{
"id":"mydoc",
"popularity":{"inc":20}
}
Since internally an update is "retrieve document, change value, reindex document", all fields has to be set as stored. If you're using the default schemaless .. schema .. in 6.2, all fields are stored by default. If you're using a custom schema or has manually changed fields through the Schema API, you'll have to make sure they're all set as stored.
Update:
For SolrJ, something like this should work (from Yonik's post):
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "test");
Map<String, String> cmd2 = new HashMap<>();
cmd1.put("inc", "20");
doc.addField("field1", cmd1);
client.add(collection, doc);
Upvotes: 2