I'm facing issues with collate
in Phrase Suggester.
Please see this reproduction:
PUT /test/test/1
{
"CompanyName": "coca-cola"
}
POST /test/_search
{
"size": 0,
"suggest": {
"DidYouMean": {
"text": "coce",
"phrase": {
"field": "_all",
"size": 50,
"direct_generator": [
{
"field": "_all",
"suggest_mode": "popular",
"min_word_length": 3
}
],
"collate": {
"query": {
"match": {
"CompanyName": {
"query": "{{suggestion}}",
"operator": "and"
}
}
},
"prune": true
}
}
}
}
}
It brings me this result with "collate_match": true
:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0,
"hits": []
},
"suggest": {
"DidYouMean": [
{
"text": "coce",
"offset": 0,
"length": 4,
"options": [
{
"text": "coca",
"score": 0.6531368,
"collate_match": true
},
{
"text": "cola",
"score": 0.5476822,
"collate_match": true
}
]
}
]
}
}
But when I create a template using this query:
PUT /_search/template/suggest
{
"template": {
"size": 0,
"suggest": {
"DidYouMean": {
"text": "{{SearchPhrase}}",
"phrase": {
"field": "_all",
"size": 50,
"direct_generator": [
{
"field": "_all",
"suggest_mode": "popular",
"min_word_length": 3
}
],
"collate": {
"query": {
"match": {
"CompanyName": {
"query": "{{suggestion}}",
"operator": "and"
}
}
},
"prune": true
}
}
}
}
}
}
And call it using this:
POST /test/_search/template
{
"template": {
"id": "suggest"
},
"params": {
"SearchPhrase": "coca cole"
}
}
I'm getting false results:
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0,
"hits": []
},
"suggest": {
"DidYouMean": [
{
"text": "coca cole",
"offset": 0,
"length": 9,
"options": [
{
"text": "coca cola",
"score": 0.4727091,
"collate_match": false
},
{
"text": "coca coca",
"score": 0.39638618,
"collate_match": false
}
]
}
]
}
}
How do I resolve it?