我在拥有3000个文档的核心中有一个Solr索引。
我想根据唯一键PaperID修改整个核心中单个字段的值。
我使用以下java代码,但不是更新现有值,而是添加新文档。
if (solrDocument.get("PaperID").equals(solrDocument2.get("PaperID"))) {
String Mscore = (String) solrDocument.get("ID");
String ModifyScore = (String) solrDocument.get("Author");
//solrDocument.setField("ID", ModifyScore);
//update the field
System.out.println(Mscore);
System.out.println(ModifyScore);
System.out.println(solrDocument2.get("Mscore") + "\n");
SolrInputDocument sid = new SolrInputDocument();
Map<String, Object> fieldModifier = new HashMap<String, Object>(1);
fieldModifier.put("set", ModifyScore);
sid.setField("ID", fieldModifier);
//solr.add(sid);
solr.commit();
}
任何人都可以相应地指导我......最好的问候
答案 0 :(得分:0)
您的代码没有更改任何内容,因为您已注释掉.add
命令。并且您必须在ID字段中使用实际ID,因为Solr将不知道要更新的文档。 field you're changing should have the fieldModifier attached:
SolrInputDocument doc = new SolrInputDocument();
Map<String, String> fieldModifier = new HashMap<String, String>();
// Change ModifyScore to the new value, since you're just using the current value now..
fieldModifier.put("set", ModifyScore);
doc.addField("ID", Mscore);
doc.addField("Author", fieldModifier);
solr.add(doc);
solr.commit();