Reputation: 22013
I have a fairly simple need to do a conditional update in Solr, which is easily accomplished in MySQL.
For example,
<id>
<id>
s, in which case Solr would update the existing records with the same <id>
s<dateCreated>
and I would like to only update a <doc>
if the new <dateCreated>
is greated than the old <dateCreated>
(this applies to duplicate <id>
s only, of course)How would I be able to accomplish such a thing?
The context is trying to combat race conditions resulting in multiple adds for the same ID but executing in the wrong order.
Thanks.
Upvotes: 5
Views: 1929
Reputation: 4614
As of solr 4.0, optimistic concurrency is enabled via the _version_
field.
http://yonik.com/solr/optimistic-concurrency/
To enable, you need to make sure your schema.xml contains
<field name="_version_" type="long" indexed="true" stored="true"/>
and in solrconfig.xml
<updateHandler class="solr.DirectUpdateHandler2">
<updateLog>
<str name="dir">${solr.data.dir:}</str>
</updateLog>
</updateHandler>
Upvotes: 2
Reputation: 1573
With really custom addition logic like this, I find that writing your own client side updater works better. It keeps you from mucking around in Solr internals, which makes it easier to update in the future. You can definitly do this in SolrJ, but if you aren't a Java dev, there is probably a clientside library in your own preferred language... PHP, Python, Ruby, C# etc...
The rsolr Ruby gem (http://github.com/mwmitchell/rsolr/tree/master) makes it VERY easy to hack together a custom load script.
Upvotes: 1
Reputation: 99720
I can think of two ways:
UpdateHandler
and override addDoc
to implement that checking.Remember that Solr is not a database, comparing it to MySQL is comparing apples and oranges.
Upvotes: 2