代码之家  ›  专栏  ›  技术社区  ›  anon

Elasticsearch:自动完成空格搜索示例不起作用

  •  0
  • anon  · 技术社区  · 7 年前

    目标是:

    The Hitchhikers Guide ,以下搜索将显示该文档:

    • hitch
    • the hit
    • hitchhikers gu

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

    • hiker
    • uid
    • guide th

    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" 
                    }
                }
            }
        }
    }
    

    然后测试分析仪:

    发布我的测试/分析

    {
      "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
    

    hitchhikersg , hitchhikersgu

    这意味着 搭便车的顾

    有什么建议吗?

    0 回复  |  直到 7 年前
    推荐文章