Elasticsearch术语建议未按预期工作

时间:2016-07-27 06:58:09

标签: search elasticsearch lucene

我有一个名为 title 的字段,其中包含以下映射。

{
 "title": {
   "type": "string"
}

在为拼写检查执行术​​语建议时,它没有按预期给出结果。

对于查询lenovo a1000,它返回的结果如下。

[spell_suggestion] => Array
        (
            [0] => Array
                (
                    [text] => lenovo
                    [offset] => 0
                    [length] => 6
                    [options] => Array
                        (
                        )

                )

            [1] => Array
                (
                    [text] => a1000
                    [offset] => 7
                    [length] => 5
                    [options] => Array
                        (
                            [0] => Array
                                (
                                    [text] => a1018
                                    [score] => 0.6
                                    [freq] => 1
                                )

                            [1] => Array
                                (
                                    [text] => a102
                                    [score] => 0.5
                                    [freq] => 1
                                )

                            [2] => Array
                                (
                                    [text] => a104
                                    [score] => 0.5
                                    [freq] => 1
                                )

                            [3] => Array
                                (
                                    [text] => a108
                                    [score] => 0.5
                                    [freq] => 1
                                )

                        )

                )

        )

)

但索引的标题包含 lenovo a1000

我使用以下查询进行拼写检查。

{
    "spell_suggestion": {
        "text": "lenovo a1000",
        "term": {
            "field": "title",
            "sort": "score",
            "prefix_length": 3
        }
    }
}

为什么elasticsearch没有返回索引中已有的术语。 我做错了什么或丢失了吗?请建议。

1 个答案:

答案 0 :(得分:0)

有一个选项suggest_mode,默认为:

missing: Only provide suggestions for suggest text terms that are not in the index. This is the default. 

尝试将其更改为:

always: Suggest any matching suggestions based on terms in the suggest text. 

参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-term.html#_common_suggest_options