Elasticsearch Autocomplete - Completion suggestion from dot & whitespace for matching input

本秂侑毒 提交于 2019-12-25 08:15:11

问题


I am trying to create auto-complete suggest based on title (string as "Hunter Game", "Hunter", "HunterGame", "Hunter-Game") and package name (string as "az.com.hsz.hunter.game", "az.com.hsz.hunter-game", "az.com.hsz.hunter_game", "az.com.hsz.hunterGame").

Mapping is as follow:

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

Document with Suggestion String is:

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

Index Setting:

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

I am expecting to get suggestion Hunter Game, for query az.com.hsz.hunter.game or Hunter Game, which is either by title or package name. But for document with input "input": "[az.com.hsz.hunter.game, Hunter Game]" , getting expected suggetion for first input value az.com.hsz.hunter.game not with second Hunter Game. If input is reversed "input": "[Hunter Game, az.com.hsz.hunter.game]" suggestion working for Hunter Game, but not with az.com.hsz.hunter.game.

How make it work?


回答1:


I think by accidently you are making input a whole string rather than list of strings.

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

will work.

currently "[az.com.hsz.hunter.game, Hunter Game]" is considered one string and hence you get back the result according to whatever is the first character.



来源:https://stackoverflow.com/questions/40275013/elasticsearch-autocomplete-completion-suggestion-from-dot-whitespace-for-mat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!