Domanda

My uniqueKey is defined as:

<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
<uniqueKey>id</uniqueKey>

I load several docs into Solr with its corresponding "id" field, what i need now is UPDATE "id" value, It is possible?

When I try to do that I get this error:

Document contains multiple values for uniqueKey field

I am using Apache Solr 4.3.0

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top