Sorting by 2 fields failing


(Declan Mungovan) #1

I'm using a Nest SearchDescriptor to retrieve different document types from an index. The documents are: contact and invoice. Currently the search descriptor sorts on two different fields. I've simplified the search descriptor to show how the sorting works:

     .Sort(st => st.Field(f => f.Field("_score").Descending()))
     .Sort(st => st.Field(f2 => f2.Field("invoiceDate").Descending().IgnoreUnmappedFields()))

The document type contact doesn't contain a field for "invoiceDate" (only the invoice document does). I find that when this second sort is added it messes up with the sorting for score with contacts (but not invoices that contains this information) i.e. just having the single _score sorting returns the highest ranking document in contacts, but adding the secondary sorting field ("invoiceDate") now results in the highest score contact document not being returned in order.

I also tried adding the .MissingLast() property and multiple different combinations of properties on the SearchDescriptor but to no avail. When I replace the secondary search field with one that is actually in contact (e.g. contactName, or even an empty string) then I find that the correctly ordered results are returned.

I had asked this question on stackoverflow but there was no solution found:


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.