You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by ~$alpha` <la...@gmail.com> on 2017/03/07 12:30:32 UTC
Solr Update If Record Exists ?
*SOLR_URL/update -d \'
[
{"id" : "1",
"ONLINE" : {"set":"1"}
}
]'*
I am using solr6.3. Above command works fine as it updates online flag to 1
for id=1. But the issue is if the record is not present then it adds a value
as id=1 and online=1 which is not desired.
So question is, is it possible that so updates the value only if the record
is present in the solr.
--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-Update-If-Record-Exists-tp4323767.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Solr Update If Record Exists ?
Posted by "alessandro.benedetti" <a....@sease.io>.
As Alex suggested, _version_ is a special field which can be used in atomic
updates with a special semantic :
"If the content in the _version_ field is equal to '1', then the document
must simply exist. In this case, no version matching occurs, but if the
document does not exist, the updates will be rejected."
From the wiki
Adding that check to update json will not check that the _version_ is 1, but
apply a special semantic ( as defined in the documentation).
Anyway I second Alex in his observation, if by any chance you are using the
_version_ field in a custom way, would be better to use a different field
for your own logic.
Cheers
-----
---------------
Alessandro Benedetti
Search Consultant, R&D Software Engineer, Director
Sease Ltd. - www.sease.io
--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-Update-If-Record-Exists-tp4323767p4324568.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Solr Update If Record Exists ?
Posted by Alexandre Rafalovitch <ar...@gmail.com>.
I don't understand your clarification. _version_ is a special field with
semantic described in the link I gave. Do you have your own, accidentally
with the same name?
Regards,
Alex
On 9 Mar 2017 3:56 AM, "~$alpha`" <la...@gmail.com> wrote:
> My version is timestamp.
> <long name="_version_">1561379927065886720</long>
>
> So can i use it ?
>
>
>
>
> --
> View this message in context: http://lucene.472066.n3.
> nabble.com/Solr-Update-If-Record-Exists-tp4323767p4324152.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
Re: Solr Update If Record Exists ?
Posted by ~$alpha` <la...@gmail.com>.
My version is timestamp.
<long name="_version_">1561379927065886720</long>
So can i use it ?
--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-Update-If-Record-Exists-tp4323767p4324152.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Solr Update If Record Exists ?
Posted by Alexandre Rafalovitch <ar...@gmail.com>.
Try adding: _version_:1, as per Optimistic Concurrency feature:
https://cwiki.apache.org/confluence/display/solr/Updating+Parts+of+Documents#UpdatingPartsofDocuments-OptimisticConcurrency
This should work for a single document update. If you are trying to
update multiple document, this is slightly more complicated as there
will be rejections/exceptions generated. Perhaps, it can be combined
with TollerantUpdate URP:
http://www.solr-start.com/javadoc/solr-lucene/org/apache/solr/update/processor/TolerantUpdateProcessorFactory.html
Regards,
Alex.
P.s. SOLR-9530 may also be interesting, though its primary use case is
somewhat different
----
http://www.solr-start.com/ - Resources for Solr users, new and experienced
On 7 March 2017 at 07:30, ~$alpha` <la...@gmail.com> wrote:
> *SOLR_URL/update -d \'
> [
> {"id" : "1",
> "ONLINE" : {"set":"1"}
> }
> ]'*
>
> I am using solr6.3. Above command works fine as it updates online flag to 1
> for id=1. But the issue is if the record is not present then it adds a value
> as id=1 and online=1 which is not desired.
>
> So question is, is it possible that so updates the value only if the record
> is present in the solr.
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Solr-Update-If-Record-Exists-tp4323767.html
> Sent from the Solr - User mailing list archive at Nabble.com.