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 Aaron Hoffer <aa...@hoffer.org> on 2019/11/27 22:41:08 UTC

Prevent Solr overwriting documents

We want to prevent Solr from overwriting an existing document if document's
ID already exists in the core.

This unit test fails because the update/overwrite is permitted:

public void testUpdateProhibited() {
  final Index index = baseInstance();
  indexRepository.save(index);
  Index index0 = indexRepository.findById(INDEX_ID).get();
  index0.setContents("AAA");
  indexRepository.save(index0);
  Index index1 = indexRepository.findById(INDEX_ID).get();
  assertThat(index, equalTo(index1));
}


The failure is:
Expected: <Index(contents=AAA, id=a2d8464ed41b4766a888617ecbcac573, ...>
but: was <Index(contents=Winterfell, id=a2d8464ed41b4766a888617ecbcac573,
...>

What do I need to do prevent the second save from overwriting the existing
document?

I commented out the updateHandler in the solr config file, to no effect.
We are using Spring Data with Solr 8.1.
In the core's schema, id is defined as unique  like this:
<uniqueKey>id</uniqueKey>

Re: Prevent Solr overwriting documents

Posted by Walter Underwood <wu...@wunderwood.org>.
That would be “do-not-overwrite”.

wunder
Walter Underwood
wunder@wunderwood.org
http://observer.wunderwood.org/  (my blog)

> On Nov 27, 2019, at 4:38 PM, Walter Underwood <wu...@wunderwood.org> wrote:
> 
> Even if that works, it is evil as something to leave in a client codebase. Maybe a do-no-overwrite flag would be useful.
> 
> wunder
> Walter Underwood
> wunder@wunderwood.org
> http://observer.wunderwood.org/  (my blog)
> 
>> On Nov 27, 2019, at 3:24 PM, Alexandre Rafalovitch <ar...@gmail.com> wrote:
>> 
>> How about Optimistic Concurrency with _version_ set to negative value?
>> 
>> You could inject that extra value in URP chain if need be.
>> 
>> Regards,
>>   Alex
>> 
>> On Wed, Nov 27, 2019, 5:41 PM Aaron Hoffer, <aa...@hoffer.org> wrote:
>> 
>>> We want to prevent Solr from overwriting an existing document if document's
>>> ID already exists in the core.
>>> 
>>> This unit test fails because the update/overwrite is permitted:
>>> 
>>> public void testUpdateProhibited() {
>>> final Index index = baseInstance();
>>> indexRepository.save(index);
>>> Index index0 = indexRepository.findById(INDEX_ID).get();
>>> index0.setContents("AAA");
>>> indexRepository.save(index0);
>>> Index index1 = indexRepository.findById(INDEX_ID).get();
>>> assertThat(index, equalTo(index1));
>>> }
>>> 
>>> 
>>> The failure is:
>>> Expected: <Index(contents=AAA, id=a2d8464ed41b4766a888617ecbcac573, ...>
>>> but: was <Index(contents=Winterfell, id=a2d8464ed41b4766a888617ecbcac573,
>>> ...>
>>> 
>>> What do I need to do prevent the second save from overwriting the existing
>>> document?
>>> 
>>> I commented out the updateHandler in the solr config file, to no effect.
>>> We are using Spring Data with Solr 8.1.
>>> In the core's schema, id is defined as unique  like this:
>>> <uniqueKey>id</uniqueKey>
>>> 
> 


Re: Prevent Solr overwriting documents

Posted by Walter Underwood <wu...@wunderwood.org>.
Even if that works, it is evil as something to leave in a client codebase. Maybe a do-no-overwrite flag would be useful.

wunder
Walter Underwood
wunder@wunderwood.org
http://observer.wunderwood.org/  (my blog)

> On Nov 27, 2019, at 3:24 PM, Alexandre Rafalovitch <ar...@gmail.com> wrote:
> 
> How about Optimistic Concurrency with _version_ set to negative value?
> 
> You could inject that extra value in URP chain if need be.
> 
> Regards,
>    Alex
> 
> On Wed, Nov 27, 2019, 5:41 PM Aaron Hoffer, <aa...@hoffer.org> wrote:
> 
>> We want to prevent Solr from overwriting an existing document if document's
>> ID already exists in the core.
>> 
>> This unit test fails because the update/overwrite is permitted:
>> 
>> public void testUpdateProhibited() {
>>  final Index index = baseInstance();
>>  indexRepository.save(index);
>>  Index index0 = indexRepository.findById(INDEX_ID).get();
>>  index0.setContents("AAA");
>>  indexRepository.save(index0);
>>  Index index1 = indexRepository.findById(INDEX_ID).get();
>>  assertThat(index, equalTo(index1));
>> }
>> 
>> 
>> The failure is:
>> Expected: <Index(contents=AAA, id=a2d8464ed41b4766a888617ecbcac573, ...>
>> but: was <Index(contents=Winterfell, id=a2d8464ed41b4766a888617ecbcac573,
>> ...>
>> 
>> What do I need to do prevent the second save from overwriting the existing
>> document?
>> 
>> I commented out the updateHandler in the solr config file, to no effect.
>> We are using Spring Data with Solr 8.1.
>> In the core's schema, id is defined as unique  like this:
>> <uniqueKey>id</uniqueKey>
>> 


Re: Prevent Solr overwriting documents

Posted by Alexandre Rafalovitch <ar...@gmail.com>.
Oops. And the link...
https://lucene.apache.org/solr/guide/6_6/updating-parts-of-documents.html#UpdatingPartsofDocuments-OptimisticConcurrency

On Wed, Nov 27, 2019, 6:24 PM Alexandre Rafalovitch, <ar...@gmail.com>
wrote:

> How about Optimistic Concurrency with _version_ set to negative value?
>
> You could inject that extra value in URP chain if need be.
>
> Regards,
>     Alex
>
> On Wed, Nov 27, 2019, 5:41 PM Aaron Hoffer, <aa...@hoffer.org> wrote:
>
>> We want to prevent Solr from overwriting an existing document if
>> document's
>> ID already exists in the core.
>>
>> This unit test fails because the update/overwrite is permitted:
>>
>> public void testUpdateProhibited() {
>>   final Index index = baseInstance();
>>   indexRepository.save(index);
>>   Index index0 = indexRepository.findById(INDEX_ID).get();
>>   index0.setContents("AAA");
>>   indexRepository.save(index0);
>>   Index index1 = indexRepository.findById(INDEX_ID).get();
>>   assertThat(index, equalTo(index1));
>> }
>>
>>
>> The failure is:
>> Expected: <Index(contents=AAA, id=a2d8464ed41b4766a888617ecbcac573, ...>
>> but: was <Index(contents=Winterfell, id=a2d8464ed41b4766a888617ecbcac573,
>> ...>
>>
>> What do I need to do prevent the second save from overwriting the existing
>> document?
>>
>> I commented out the updateHandler in the solr config file, to no effect.
>> We are using Spring Data with Solr 8.1.
>> In the core's schema, id is defined as unique  like this:
>> <uniqueKey>id</uniqueKey>
>>
>

Re: Prevent Solr overwriting documents

Posted by Alexandre Rafalovitch <ar...@gmail.com>.
How about Optimistic Concurrency with _version_ set to negative value?

You could inject that extra value in URP chain if need be.

Regards,
    Alex

On Wed, Nov 27, 2019, 5:41 PM Aaron Hoffer, <aa...@hoffer.org> wrote:

> We want to prevent Solr from overwriting an existing document if document's
> ID already exists in the core.
>
> This unit test fails because the update/overwrite is permitted:
>
> public void testUpdateProhibited() {
>   final Index index = baseInstance();
>   indexRepository.save(index);
>   Index index0 = indexRepository.findById(INDEX_ID).get();
>   index0.setContents("AAA");
>   indexRepository.save(index0);
>   Index index1 = indexRepository.findById(INDEX_ID).get();
>   assertThat(index, equalTo(index1));
> }
>
>
> The failure is:
> Expected: <Index(contents=AAA, id=a2d8464ed41b4766a888617ecbcac573, ...>
> but: was <Index(contents=Winterfell, id=a2d8464ed41b4766a888617ecbcac573,
> ...>
>
> What do I need to do prevent the second save from overwriting the existing
> document?
>
> I commented out the updateHandler in the solr config file, to no effect.
> We are using Spring Data with Solr 8.1.
> In the core's schema, id is defined as unique  like this:
> <uniqueKey>id</uniqueKey>
>