我正在使用Elasticsearch短语Suggester来纠正用户的拼写错误。一切都如我所料,除非用户输入一个查询,它的第一个字母拼写错误。在这种情况下,短语suggester不返回任何内容或返回意外结果。
我的文档和查询与
phrase suggester
:
POST test/test?refresh=true
{"title": "noble warriors"}
POST test/test?refresh=true
{"title": "nobel prize"}
POST test/_search
{
"suggest": {
"text": "noble prize",
"simple_phrase": {
"phrase": {
"field": "title.trigram",
"size": 1,
"gram_size": 3,
"direct_generator": [ {
"field": "title.trigram",
"suggest_mode": "always"
} ],
"highlight": {
"pre_tag": "<em>",
"post_tag": "</em>"
}
}
}
}
}
{
"_shards": ...
"hits": ...
"timed_out": false,
"took": 3,
"suggest": {
"simple_phrase" : [
{
"text" : "mobel prize",
"offset" : 0,
"length" : 11,
"options" : []
}
]
}
}
第4个字母拼写错误的示例:
{
"_shards": ...
"hits": ...
"timed_out": false,
"took": 3,
"suggest": {
"simple_phrase" : [
{
"text" : "noble prize",
"offset" : 0,
"length" : 11,
"options" : [ {
"text" : "nobel prize",
"highlighted": "<em>nobel</em> prize",
"score" : 0.5962314
}]
}
]
}
}