首页 > 解决方案 > Elasticsearch:带空格的自动完成搜索示例不起作用

问题描述

目标:

如果我有一个带有 title 的文档The Hitchhikers Guide,则以下搜索会显示该文档:

以下搜索不会显示该文档:

我正在关注这篇文章: https ://medium.com/@davedash/writing-a-space-ignoring-autocompleter-with-elasticsearch-6c3c28e3a974

但我似乎无法在索引/分析步骤中获得预期的结果。我在 ES 5.3 和 6.3 上试过这个。

这是我到目前为止所拥有的:

我的映射:

把我的测试

{
    "settings" : {
        "index":{
            "analysis":{
                "filter": {
                    "autocomplete_filter": {
                        "type": "edge_ngram",
                        "min_gram": "1",
                        "max_gram": "30"
                    },
                    "autocomplete_word_joiner": {
                        "type": "word_delimiter",
                        "catenate_all": true
                    }
                },
                "analyzer":{
                    "product_name_autocomplete_analyzer": {
                        "type": "custom",
                        "tokenizer": "keyword",
                        "filter": [
                            "lowercase",
                            "autocomplete_word_joiner",
                            "autocomplete_filter"
                        ]   
                    }
                }
            }
        }
    },
    "mappings" : {
        "doc" : {
            "properties": {
                "name": {
                    "type": "text", 
                    "store": true,
                    "analyzer": "product_name_autocomplete_analyzer",
                    "term_vector": "with_positions_offsets" 
                }
            }
        }
    }
}

然后测试分析仪:

发布 my_test/_analyze

{
  "analyzer": "product_name_autocomplete_analyzer",
  "text": "the hitchhikers guide"
}

以下是代币:

t
th
the
theh
thehi
thehit
...
thehitchikersguid
thehitchikersguide
h
hi
hit
hitc
hitch
...
hitchiker
hitchikers
g
gu
...
guide

这是出乎意料的,因为它丢失hitchhikersghitchhikersgu

这意味着搜索hitchhikers gu失败,这就是我所看到的。

有什么建议吗?

标签: elasticsearchlucenewhitespacen-gram

解决方案


推荐阅读