If I understand your concern correctly, you want to perform an atomic
update only if the document already exists, else just want the update to be
rejected (as in don't want a new document to be added)? . If that's
correct, add "_version_" field with value 1 in your document as below :

{
"id":"1",
"_version_":1,
"month":{"set":1}
}

Check out optimistic concurrency : Updating Parts of Documents | Apache
Solr Reference Guide 8.5
<https://solr.apache.org/guide/8_5/updating-parts-of-documents.html#optimistic-concurrency>

"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."

- Rahul

On Thu, May 13, 2021 at 9:55 PM alex noname <[email protected]> wrote:

> Hi everyone,
>
> I'm doing some solr update coding and the solr version I'm using is 8.5.1
>
> So far I can successfully do a partial update by sending
>
> {
>     "id":"1",
>     "month":{"set":1}
> }
>
> to the /update handler. This way I can update the month filed to be 1 for
> record with id 1.
>
>
> *But the thing is, if there's no existing record with id 1, a new record
> will be created with provided id and month info.*
>
> One workaround is, before issuing an update, I do a solr query for id:1,
> only when the result is not empty then I do the update.
>
> Just want to know, if there's a better way to do this?
>
>
>
> Thanks
>

Reply via email to