When I add Sort() in elasticsearch (NEST) I don't get any hits

Viewed 1720

When I sort like this:

.Sort(sortDescriptor => sortDescriptor.Descending(product => product.TopProduct))

I have no hits. Any idea why? Is the syntax wrong or what? I got this from the official NEST/elasticsearch docs site.

SOLUTION

I had to add .Suffix("keyword") like this:

.Sort(sortDescriptor => sortDescriptor.Descending(product => product.TopProduct.Suffix("keyword")))

And it worked. I had to use the "keyword" subfield on "TopProduct".

Default mapping for String propertiesedit: When using Auto Mapping, the inferred mapping for a string POCO type is a text datatype with multi fields including a keyword sub field

Source: https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/multi-fields.html#_default_mapping_for_string_properties

If you index a string with no mapping, ES in 5.0+ now automatically creates a text version and a keyword version (under .keyword) of the field. - dakroneLee HinmanElastic Team Member

Source: https://discuss.elastic.co/t/is-sorting-on-text-string-field-no-longer-available-in-5-x/68586/4

This worked but could someone explain to me how the text and keyword datatypes work?

0 Answers
Related