Elasticsearch自动填充 - 点和点的完成建议用于匹配输入的空格

时间:2016-10-27 02:09:45

标签: elasticsearch autocomplete lucene autosuggest search-suggestion

我正在尝试根据标题(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
          }
        }
      }
    }
  }
}

带有Suggestion String的文档是:

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

我希望得到建议猎人游戏,查询az.com.hsz.hunter.gameHunter Game,这可以是标题或包名。但对于输入为"input": "[az.com.hsz.hunter.game, Hunter Game]"的文档,第一个输入值az.com.hsz.hunter.game的预期suggetion不是第二个Hunter Game。 如果输入被撤消"input": "[Hunter Game, az.com.hsz.hunter.game]"建议适用于Hunter Game,但不适用于az.com.hsz.hunter.game

如何使其有效?

1 个答案:

答案 0 :(得分:0)

我认为你意外地将输入作为整个字符串而不是字符串列表。

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

会奏效。

当前"[az.com.hsz.hunter.game, Hunter Game]"被认为是一个字符串,因此您可以根据第一个字符获取结果。