Thanks @Marcus - if I use the function score with a field as you describe it means I always sort the documents according to this field and this is not what I want to achieve.
Maybe I’ll explain my problem with an example:
let’s assume I have 5 documents in a collection and the collection is not changing:
object_id, numeric_field, string_field
A, 1, ‘abc’
B, 2, ‘abc’
C, 2, ‘abc’
D, 3, ‘abc’
E, 3, ‘def’
I want to display the documents that contain ‘abc’ in their string_field and sort them by their numeric_value, so I’ll use this search stage:
I also want to display the documents in pages of 2.
So, for getting the first page a stage of limit:2 will be added to the pipe, and for getting the second page two stages of skip:2,limit:2 will be added to the pipe.
If I perform the two queries for getting the two pages over and over I want to always get A,B in first page and C,D in second page.
Because B,C have the same numeric field value they will both get the same search score and as far as I understand it is possible that I will get a first page of A,C or second page of B,D.
So is there something I can do to guarantee the consistency?
BTW I tried to check consistency of the same query with real data and it do seems like i always get the same order of results even when I have documents with same search score.
Might it work this way because the collection is not sharded so mongot always scan the documents in same order and so it outputs results in same order?