我的搜索配置到目前为止工作正常,但我无法弄清楚如何让NGram Tokenizer搜索像&,+,²等符号。
当我使用'标准'标记器时,它会搜索符号并给出正确的结果。所以我认为我与NGram Tokenizer的映射是错误的。
这是我的映射配置:
"settings": {
"number_of_shards": 4,
"analysis": {
"tokenizer": {
"ngram_tokenizer": {
"type": "nGram",
"min_gram": "1",
"max_gram": "20",
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
}
},
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
},
"whitespace_remove": {
"type": "pattern_replace",
"pattern": " ",
"replacement": ""
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "ngram_tokenizer",
"filter": [
"lowercase",
"autocomplete_filter"
]
},
"concat_analyzer": {
"filter": [
"lowercase",
"whitespace_remove",
"nGram"
],
"type": "custom",
"tokenizer": "keyword"
},
"analyzer_firstletter": {
"filter": "lowercase",
"tokenizer": "keyword"
}
}
}
和我的映射:
"mappings": {
"devicemodel": {
"_timestamp": {
"enabled": true,
"store": "yes"
},
"_id": {
"path": "id"
},
"properties": {
"id": {
"store": "yes",
"type": "string"
},
"devicemodelID": {
"store": "yes",
"type": "string"
},
"devicemodelcode": {
"store": "yes",
"type": "string",
"index_analyzer": "autocomplete",
"search_analyzer": "standard",
"search_quote_analyzer": "autocomplete",
"term_vector": "with_positions_offsets",
"fields": {
"firstletter": {
"analyzer": "analyzer_firstletter",
"type": "string"
}
}
},
"devicemodel": {
"store": "yes",
"type": "string",
"index_analyzer": "autocomplete",
"search_analyzer": "standard",
"search_quote_analyzer": "autocomplete",
"term_vector": "with_positions_offsets",
"fields": {
"concat": {
"type": "string",
"index_analyzer": "concat_analyzer",
"search_analyzer": "standard"
}
}
},