【问题标题】:Autocomplete with Elasticsearch使用 Elasticsearch 自动完成
【发布时间】:2015-03-25 09:17:02
【问题描述】:

我正在尝试使用 Elasticsearch 来索引城市数据库并在字段上自动完成。

这是我的 FOSElasticaBundle 配置:

fos_elastica:
    indexes:
        xxxxxxx:
            settings:
                index:
                    analysis:
                        analyzer:
                            custom_analyzer:
                                type:      custom
                                tokenizer: nGram
                                filter:    [lowercase, asciifolding, stopwords_fr, elision, snowball_fr, word_delimiter]
                            custom_search_analyzer:
                                type:      custom
                                tokenizer: standard
                                filter:    [lowercase, asciifolding, stopwords_fr, elision, snowball_fr, word_delimiter]
                        tokenizer:
                            nGram:
                              type:     nGram
                              min_gram: 4
                              max_gram: 20
                        filter:
                            snowball_fr:
                                type:     snowball
                                language: French
                            elision:
                                type:     elision
                                articles: [l, m, t, qu, n, s, j, d]
                            stopwords_fr:
                                type:        stop
                                stopwords:   [_french_]
                                ignore_case: true
            types:
                cities:
                    mappings:
                        id:
                        name: { search_analyzer: custom_analyzer, index_analyzer: custom_analyzer, type: string, store: yes }
                persistence:
                    driver:     orm
                    model:      XXXXX\MainBundle\Entity\City
                    provider:   { query_builder_method: createSearchIndexQueryBuilder }
                    listener:   ~
                    finder:     ~
                    repository: XXXXX\SearchBundle\Repository\CitySearchRepository

我的查询如下所示:

{
  "query": {
    "match": {
      "name": "xxxxxx"
    }
  }
}

但我的问题就在这里:

  • 当我输入 “Pa” 时,我得到 242 个结果(ok)
  • 当我输入 “Par” 时,我得到 no results (WTF)
  • 当我输入 “Pari” 时,我得到 22 个结果(ok)
  • 当我输入 “Paris” 时,我得到 10 个结果(ok)

这是我第一次使用 Elasticsearch,我认为解决方案就在附近,但如果有人遇到同样的问题,我很想了解更多信息。

谢谢,祝你有美好的一天;)

【问题讨论】:

    标签: symfony autocomplete elasticsearch foselasticabundle


    【解决方案1】:

    在您的查询中,您正在执行一个匹配。这意味着您将寻找具有您正在寻找的(分析的)价值的文档。

    你应该看看completion suggester,这是实现自动完成建议的最佳方式。

    如果你很懒,你可以使用prefix query

    {
        "prefix" : { "user" : "Pa" }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-03-05
      • 2016-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-14
      • 2017-09-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多