You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@solr.apache.org by Cesar Delgado <be...@gmail.com> on 2023/03/22 18:22:36 UTC

Is there a way to do a kind of "check and put" on index?

Hello,

I have a schema with some date field and some long fields: (example)

<field name="created_at" type="date" indexed="true" required="true" stored="false" docValues="true"/>
<field name="edited_at" type="date" indexed="true" required="false" stored="false" docValues="true"/>
<dynamicField name="*_count" type="long" indexed="true" stored="false" docValues="true"/>
Some of the documents might be modified and what I’d like to do is replace the document in the index IF any of the *_count values are greater than what is in Solr already or if the edited_at value is greater than the created_at or greater than the previous edited_at value. At the moment what I’m doing is inserting a document with _version_ = -1 and if I get an error then I get the document, do the checks I’ve explained in the application, and reindex if I need to. I’m curious to know if this is something I can push down to Solr? Doing 2 searches and 2 PUTs per document that is modified seems a bit excessive.

Many thanks for the help.

-Cesar 

Re: Is there a way to do a kind of "check and put" on index?

Posted by Shawn Heisey <ap...@elyograg.org>.
On 3/22/23 12:22, Cesar Delgado wrote:
> <field name="created_at" type="date" indexed="true" required="true" stored="false" docValues="true"/>
> <field name="edited_at" type="date" indexed="true" required="false" stored="false" docValues="true"/>
> <dynamicField name="*_count" type="long" indexed="true" stored="false" docValues="true"/>
> Some of the documents might be modified and what I’d like to do is replace the document in the index IF any of the *_count values are greater than what is in Solr already or if the edited_at value is greater than the created_at or greater than the previous edited_at value. At the moment what I’m doing is inserting a document with _version_ = -1 and if I get an error then I get the document, do the checks I’ve explained in the application, and reindex if I need to. I’m curious to know if this is something I can push down to Solr? Doing 2 searches and 2 PUTs per document that is modified seems a bit excessive.

I do not know of anything built into Solr to do that.

Any capability like this that we might implement would be almost as slow 
as doing it yourself ... there would be no great advantage other than 
ease of use.  There are a lot of things that are simply better to do 
client-side.

Why are you doing two queries and two puts?  The best way to handle this 
(imho) would be:  Ask for an existing entry using the uniqueKey value 
with the /get handler and then decide at that point whether you're going 
to even do the indexing.  One step if the document exists and is later 
than the proposed change, two steps if it does not exist or the existing 
document is older.

Thanks,
Shawn