Hi Per, > 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?
Given that you've set a uniqueKey-field and there already exists a document with that uniqueKey, it will delete the old one and insert the new one. There is really no difference between the semantics - updates do not exist. To create a UNIQUE-constraint as you know it from a database you have to check whether a document is already in the index *or* whether it is already pending (waiting for getting flushed to the index). Fortunately Solr manages a so called pending-set with all those documents waiting for beeing flushed to disk (Solr 3.5). I think you have to write your own DirectUpdateHandler to achieve what you want on the Solr-level or to extend Lucenes IndexWriter to do it on the Lucene-Level. While doing so, keep track of what is going on in the trunk and how Near-Real-Time-Search will change the current way of handling updates. > 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? Exactly. If you really want to get your hands on that topic I suggest you to learn more about Lucene's IndexWriter: http://lucene.apache.org/core/old_versioned_docs/versions/3_5_0/api/all/index.html?org/apache/lucene/index/IndexWriter.html Kind Regards, Em