I am seeing some unexpected behavior for a suggestion query with fuzzy turned on. The results include a number of documents with the same score (including the exact match) but the exact match is not the first one.
Using elasticsearchjs 11 with ES 2.3.5 cluster
The query is as follows:
client.suggest({
index: 'myindex',
body: {
"suggestions": {
"text": "Politics",
"completion": {
"field": "suggestTag",
"size": 10,
"fuzzy": true,
"context": {
"community": "Test"
}
}
}
}
});
The result is:
{
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"suggestions": [
{
"text": "Politics",
"offset": 0,
"length": 7,
"options": [
{
"text": "Politica",
"score": 1000,
"payload": {
"_id": "Politica"
}
},
{
"text": "PoliticalTheory",
"score": 1000,
"payload": {
"_id": "PoliticalTheory"
}
},
{
"text": "Politics",
"score": 1000,
"payload": {
"_id": "Politics"
}
},
{
"text": "Poltics",
"score": 1000,
"payload": {
"_id": "Poltics"
}
},
{
"text": "Middle East Politics",
"score": 2,
"payload": {
"_id": "MiddleEastPolitics"
}
},
{
"text": "Political Campaigns",
"score": 1,
"payload": {
"_id": "PoliticalCampaigns"
}
},
{
"text": "Political Science",
"score": 1,
"payload": {
"_id": "PoliticalScience"
}
}
]
}
]
}
As you can see, the exact match for "Politics" has the same score (1000) as some of the other matches. I would expect that the exact match is the first result in that case.
The relevant piece of the mapping is:
"suggestTag": {
"type": "completion",
"analyzer": "simple",
"preserve_separators": false,
"payloads": true,
"context": {
"community": {
"type": "category",
"default": [
"*"
]
}
}
}
Is there a way to change the sort behavior/scoring in that case? I have not seen anything in this forum that deals with the suggestion query in particular.