【问题标题】:Elasticsearch Autocomplete - Completion suggestion from dot & whitespace for matching inputElasticsearch Autocomplete - 来自点和空格的完成建议以匹配输入
【发布时间】:2017-03-09 13:42:54
【问题描述】:

我正在尝试根据标题 (string as "Hunter Game", "Hunter", "HunterGame", "Hunter-Game") 和包名称 (string as "az.com.hsz.hunter.game", "az.com.hsz.hunter-game", "az.com.hsz.hunter_game", "az.com.hsz.hunterGame") 创建自动完成建议。

映射如下:

{
  "app-search-test": {
    "mappings": {
      "package": {
        "properties": 
         {"title": {
            "type": "string",
            "analyzer": "autocomplete"
          },
          "package_name": {
            "type": "string"
          },
          "title-suggest": {
            "type": "completion",
            "analyzer": "simple",
            "payloads": true,
            "preserve_separators": false,
            "preserve_position_increments": true,
            "max_input_length": 50
          }
        }
      }
    }
  }
}

带有建议字符串的文档是:

{
    "title": "HUnter Game",
    "package_name": "az.com.hsz.hunter.game",
    "title-suggest": {
                "output": "Hunter Game",
                "input": "[az.com.hsz.hunter.game, Hunter Game]",
                "payload": {
                  "package_name": "az.com.hsz.hunter.game",
                  "icon": "<some-url>",
                  "developer": "Vish",
                  "id": "az.com.hsz.hunter.game",
                  "title": "Hunter Game"
                }
              }
}

索引设置:

"analysis": {
          "filter": {
            "words_splitter": {
              "type": "word_delimiter",
              "preserve_original": "true",
              "catenate_all": "true"
            },
            "ngram": {
              "type": "ngram",
              "min_gram": "2",
              "max_gram": "15"
            }
          },
          "analyzer": {
            "autocomplete": {
              "type": "custom",
              "filter": [
                "standard",
                "lowercase",
                "stop",
                "kstem",
                "ngram",
                "words_splitter"
              ],
              "tokenizer": "keyword"
            }
          }
        }

我希望得到建议 Hunter Game,查询 az.com.hsz.hunter.gameHunter Game,可以是标题或包名称。但是对于带有输入 "input": "[az.com.hsz.hunter.game, Hunter Game]" 的文档,获得第一个输入值 az.com.hsz.hunter.game 而不是第二个 Hunter Game 的预期建议。 如果输入颠倒了"input": "[Hunter Game, az.com.hsz.hunter.game]" 建议适用于Hunter Game,但不适用于az.com.hsz.hunter.game

如何让它工作?

【问题讨论】:

    标签: elasticsearch autocomplete lucene autosuggest search-suggestion


    【解决方案1】:

    我认为您无意中将 input 设置为整个字符串而不是字符串列表。

    "input": ["az.com.hsz.hunter.game", "Hunter Game"]
    

    会起作用的。

    目前"[az.com.hsz.hunter.game, Hunter Game]" 被视为一个字符串,因此您可以根据第一个字符返回结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-05
      • 2020-08-21
      • 2020-07-14
      • 1970-01-01
      • 2017-09-11
      • 2022-01-22
      • 1970-01-01
      相关资源
      最近更新 更多