Solr conditional additions / updates?

I have a pretty simple need to do a conditional update in Solr, which is easy to do in MySQL.

For example,

  • I have 100 documents with a unique field <id>
  • I am sending 10 documents, some of which may be duplicated by <id>s, in which case Solr will update existing records with the same <id>s
  • I have a field called <dateCreated>, and I would like to update only <doc>if the new one <dateCreated>is blurry than the old one <dateCreated>(this only applies to duplication <id>, of course)

How can I accomplish such a thing?

The context is trying to deal with the conditions of the race, resulting in several additions for the same identifier, but are executed in the wrong order.

Thanks.

+3
source share
3 answers

I can think of two ways:

  • Write your own UpdateHandlerand override addDocto implement this check.
  • Place the appropriate locks (critical sections) in the client code to retrieve the saved document, compare dates, and conditionally add a new document in a thread-safe manner.

Remember that Solr is not a database, comparing it with MySQL, comparing apples and oranges.

+2
source

As in solr 4.0, optimistic concurrency is activated through the field _version_.

http://yonik.com/solr/optimistic-concurrency/

To enable, you must make sure your schema.xml file 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>
+2

, , , . Solr, . SolrJ, Java, , ... PHP, Python, Ruby, # ..

rsolr Ruby (http://github.com/mwmitchell/rsolr/tree/master) script.

+1

Source: https://habr.com/ru/post/1715207/


All Articles