Data is being sorted different with identical set of data

Category: azure search

Question

Allan.Paramo on Wed, 22 Mar 2017 15:48:43


Hi, 

It looks like with an identical set of data the order by behaves different. 

In the next two screens the exact same catalog is being sorted by description but somehow the result is not the same when sorting them.  I would expect to have the same result when viewing different catalogs with identical data. 

Catalog 1: see the first two product

Catalog 2: see the first two product

The query looks like this:

$filter= true and ((effStartDate eq null or effStartDate le 2017-03-21) and (effEndDate eq null or effEndDate ge 2017-03-21)) and catId eq 2223&$orderby=shortDescSort

$filter= true and ((effStartDate eq null or effStartDate le 2017-03-21) and (effEndDate eq null or effEndDate ge 2017-03-21)) and catId eq 2224&$orderby=shortDescSort

The shortDescSort it is the field that stores the upper case version of the short description.

Does it matter the order when creating the document against the index? for identical set of data? 

Why the result when sorting isn't the same? 

is it related to the default scoring set? For this search I m not being explicit to use it.

Thanks

Allan




Replies

Bruce Johnston - MSFT on Wed, 22 Mar 2017 18:29:16


Hi Allan,

When using $orderby on a field that has non-unique values, any ties are broken using the document score. In your case, since you're only using $filter and not search, the score is always 1, so the order of documents with matching fields is non-deterministic. This is because Azure Search distributes queries across independent execution resources called shards, even on services with only a single search unit.

If you need a stable ordering for ties, you need to add a unique field like the document ID to the $orderby clause.

Allan.Paramo on Fri, 24 Mar 2017 12:05:23


Hi Bruce,

Thanks for explanation. I will test it with a unique field as part of my order by clause.

Allan