Solr支持简单的原子更新(也被称为部分更新)单文件通过字段修饰符如ADD,Inc.乐观并发控制是自动更新文件的一种方法。
Solr支持整个doc 更新几个字段,自动更新文档中的值。
set – set or replace a particular value, or remove the value if null is specified as the new valueadd – adds an additional value to a list
remove – removes a value (or a list of values) from a list
removeregex – removes from a list that match the given Java regular expression
inc – increments a numeric value by a specific amount (use a negative value to decrement)
// create the SolrJ client
HttpSolrClient client = newHttpSolrClient("http://localhost:8983/solr");
// create the document
SolrInputDocument sdoc = newSolrInputDocument();
sdoc.addField("id","book1");
Map<String,Object> fieldModifier = newHashMap<>(1);
fieldModifier.put("add","Cyberpunk");
sdoc.addField("cat", fieldModifier); // add the map as the field value
client.add( sdoc ); // send it to the solr server
client.close(); // shutdown client before we exit