It is possible to update uniqueKey in Solr 4?

后端 未结 1 1371
终归单人心
终归单人心 2021-01-23 18:59

My uniqueKey is defined as:

 


        
相关标签:
1条回答
  • 2021-01-23 19:32

    It's not directly possible. Before I get into how you can do it indirectly, I need to explain a couple of things.

    The value in the uniqueKey field is how Solr handles document updating/replacing. When you send a document in for indexing, if an existing document with the same uniqueKey value already exists, Solr will delete its own copy before indexing the new one.

    The atomic update functionality is slightly different. It lets an update add, change, or remove any field in the document except the uniqueKey field - because that's the way that Solr can identify the document.

    What you need to do is basically index a new document with all the data from the old document, and delete the old document. If all the fields in the document are available to the indexing process, then you can just index the new document, either before or after deleting the old one. Otherwise, you can query the existing doc out of Solr, make a new one and index it, and then delete the old one.

    In order to use the existing Solr document to index a new one, all fields must be stored, unless they are copyField destinations, in which case they must NOT be stored. Atomic updates (discussed above) have the same requirement. If one or more of these fields is not stored, then the search result will not contain that field and the data will be lost.

    0 讨论(0)
提交回复
热议问题