Per: Yep, you've got it. You could write a custom update handler that queried (via TermDocs or something) for the ID when your intent was to INSERT, but it'll have to be custom work. I suppose you could query with a divide-and-conquer approach, that is query for id:(1 2 58 90... all your insert IDs) and go/no-go based on whether your return had any hits, but that supposed you have some idea whether pre-existing documents are likely.....
But Solr doesn't have anything like you're looking for. Best Erick On Thu, Feb 23, 2012 at 10:32 AM, Per Steffensen <st...@designware.dk> wrote: > Em skrev: > >> Hi Per, >> >> well, Solr has no "Update"-Method like a RDBMS. It is a re-insert of the >> whole document. Therefore a document with an existing UniqueKey marks >> the old document as deleted and inserts the new one. >> > > Yes I understand. But it is not always what I want to acheive. I want an > error to occur if a document with the same id already exists, when my intent > is to INSERT a new document. When my intent is to UPDATE a document in > solr/lucene I want the old document already in solr/lucene deleted and the > new version of this document added (exactly as you explain). It will not be > possible for solr/lucene to decide what to do unless I give it some > information about my intent - whether it is INSERT or UPDATE semantics I > want. I guess solr/lucene always give me INSERT sematics when a document > with the same id does not already exist, and that it always give me UPDATE > semantics when a document with the same id does exist? I cannot decide? > >> However this is not the whole story, since this "constraint" only works >> per index/SolrCore/Shard (depending on your use-case). >> > > Yes I know. But with the right routing strategy based on id's I will be able > to acheive what I want if the feature was just there per index/core/shard. >> >> Does this help you? >> > > Yes it helps me getting sure, that what I am looking for is not there. There > is not built-in way to make solr/lucene give me an error if I try to insert > a new document with an id equal to a document already in the > index/core/shard. The existing document will always be updated (implemented > as "old deleted and new added"). Correct? >> >> Kind regards, >> Em >> > > Regards, Per Steffensen >