1

如果用户键入

jewelr

我想得到结果

jewelry

我正在使用 multi_match 查询。

4

1 回答 1

2

You could use EdgeNGram tokenizer:

http://www.elasticsearch.org/guide/reference/index-modules/analysis/edgengram-tokenizer/

Specify an index time analyzer using this,

"analysis": {
    "filter": {
        "fulltext_ngrams": {
            "side": "front",
            "max_gram": 15,
            "min_gram": 3,
            "type": "edgeNGram"
        }
    }, 
    "analyzer": {  
        "fulltext_index": {
            "type": "custom",
            "filter": [
                "standard",
                "lowercase",
                "asciifolding",
                "fulltext_ngrams"
            ],
            "type": "custom",
            "tokenizer": "standard"
    }
}

Then either specify as default index analyzer, or for a specific field mapping.

When indexing a field with value jewelry, with a 3/15 EdgeNGram, all combinations will be stored:

jew jewe jewel jewelr jewelry

Then a search for jewelr will get a match in that document.

于 2013-09-09T11:08:28.180 回答