您的位置:首页 > 其它

Solr 部分 局部字段修改 更新 删除

2015-11-26 17:19 495 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: