Update specific field in Solr

╄→尐↘猪︶ㄣ 提交于 2019-12-20 06:20:59

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/40274586/update-specific-field-in-solr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!