How to change Solr document id by SolrJ?

耗尽温柔 提交于 2019-12-12 02:54:49

问题


I use the following code to change specific field value.

SolrInputDocument solrdoc=new SolrInputDocument();
solrdoc.addField("id","book001");
Map<String,Object> fieldModifier=new HashMap<>(1);
fieldModifier.put("set","book_new_name");
solrdoc.addField("name",fieldModifier); 

But I cannot use the similar code to change Solr unique document id, exception is thrown.

solrdoc.addField("id",fieldModifier); 

Is there any solution to change the Solr document id?


回答1:


Changing the document id requires removing and re-adding the document, so delete the document (by id), then re-add the document with the new id. You can do this without committing between deleting and adding the document, so it will be seamless for any clients querying the collection.



来源:https://stackoverflow.com/questions/36004218/how-to-change-solr-document-id-by-solrj

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