Reputation: 9879
Here's the ElasticSearch query I'd like to build using NEST:
{
"from": 0,
"size": 10,
"sort": {
"_script": {
"script": "doc['name'].value=='my perfect match' ? 1 : 0",
"type" : "number",
"order" : "desc"
},
"_score": {}
},
"query": {
....
}
}
(simplified - really I'm sorting by a few more attributes. The point of the script-based sort is to promote exact matches to the top of the result set.)
Explicitly sorting by _score is not a problem...
.Sort(sort => sort.OnField("_score"))
... but NEST doesn't seem to have an equivalent operator for the script-based sort yet - or does it?
Upvotes: 1
Views: 538
Reputation: 13536
NEST supports script sorts through SortScript()
See the unit tests for them here:
https://github.com/Mpdreamz/NEST/blob/master/src/Nest.Tests.Unit/Search/Sort/SortTests.cs#L171
Upvotes: 2