1

I am new to Solr and encountered a weird behavior as I update a field and perform search.

Here's the scenario : I have a 300records in my core, I have a search query wherein I filtered the results with this

fq=IsSoldHidden:false AND IsDeleted:false AND StoreId:60 and I sort it by DateInStock asc

Everything is perfectly returning my expected results, Here is the sample top 3 results of my query :

--------------------------------------------------------------------------------------
id    | Price   | IsSoldHidden | IsDeleted | StoreId | StockNo | DateInStock 
-------------------------------------------------------------------------------------- 
27236 | 15000.0 |   false      |  false    |    60   |  A00059 | 2021-06-07T00:00:00Z
-------------------------------------------------------------------------------------- 
37580 | 0.0     |   false      |  false    |    60   |  M9202  | 2021-06-08T00:00:00Z
-------------------------------------------------------------------------------------- 
37581 | 12000   |   false      |  false    |    60   |  M9173  | 2021-06-08T00:00:00Z

but when I tried to update(AtomicUpdate to be specific) the Price field in 2nd row , and trigger a search again with the same filters requirements, the results changes to this :

--------------------------------------------------------------------------------------
id    | Price   | IsSoldHidden | IsDeleted | StoreId | StockNo | DateInStock
-------------------------------------------------------------------------------------- 
27236 | 15000.0 |   false      |  false    |    60   |  A00059 | 2021-06-07T00:00:00Z
-------------------------------------------------------------------------------------- 
37581 | 0.0     |   false      |  false    |    60   |  M9173  | 2021-06-08T00:00:00
-------------------------------------------------------------------------------------- 
37582 | 0.0     |   false      |  false    |    60   |  M1236  | 2021-06-08T00:00:00Z

and the 2nd row(37580) of the 1st results was placed at the last row(document#300).

I have researched online , and Here's what I've found

Solr changes document's score when its random field value altered

but I think the situation is different to mine, since I did not add the score as a Sort.

I am not sure why does it behave like this, Am I missing something ? Or is there anyone can explain it ?

Thanks in advance.

venalyn sudaria
  • 149
  • 1
  • 11
  • Since you didn't include the actual date in the entries returned it's hard to say - but could it be that the date is the same? in that case the internal document order in the Lucene will be the one used, and since an update is effectively a delete + an insert, the new document gets appended to the end of the index. It's also hard to say if `37580` was included at all in the result from your example. – MatsLindh Jun 10 '21 at 08:24
  • @MatsLindh, Hi I updated my post and include dates . And also I am using Atomic Update in updating the field Price. – venalyn sudaria Jun 10 '21 at 08:39

1 Answers1

2

Since the dates are identical, their internal sort order depends on their position in the index.

Updating the document marks the original document as deleted and adds a new document at the end of the index, so its position in the index changes.

If you want to have it stable, sort by date and id instead - that way the lower id will always be first when the dates are identical, and the sort will be stable.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84