我的索引设置如下:
settings: {
index.analysis.analyzer.eng_search_analyzer.filter.0: lowercase
index.analysis.analyzer.eng_search_analyzer.filter.1: icu_folding
index.analysis.analyzer.eng_search_analyzer.char_filter.0: html_strip
index.analysis.filter.eng_ngram_filter.type: nGram
index.analysis.filter.eng_ngram_filter.min_gram: 1
index.analysis.analyzer.eng_search_analyzer.tokenizer: whitespace
index.analysis.analyzer.eng_search_analyzer.filter.2: icu_normalizer
index.analysis.analyzer.eng_index_analyzer.filter.1: eng_ngram_filter
index.analysis.analyzer.eng_index_analyzer.filter.0: lowercase
index.number_of_shards: 2
index.analysis.filter.eng_ngram_filter.token_chars.1: digit
index.analysis.filter.eng_ngram_filter.token_chars.0: letter
index.analysis.filter.eng_ngram_filter.token_chars.3: symbol
index.analysis.filter.eng_ngram_filter.token_chars.2: punctuation
index.analysis.analyzer.eng_index_analyzer.type: custom
index.analysis.analyzer.eng_index_analyzer.char_filter.0: html_strip
index.analysis.analyzer.eng_index_analyzer.filter.3: icu_normalizer
index.analysis.filter.eng_ngram_filter.max_gram: 20
index.analysis.analyzer.eng_index_analyzer.filter.2: icu_folding
index.number_of_replicas: 1
index.analysis.analyzer.eng_index_analyzer.tokenizer: whitespace
index.analysis.analyzer.eng_search_analyzer.type: custom
index.version.created: 900799
index.uuid: -O-iV6ZIQh6gk1204Ec1ig
}
几个重要字段的字段映射设置如下:
{
"name": {
"type": "multi_field",
"fields": {
"name": {
"type": "string",
"index": "not_analyzed",
"omit_norms": "true",
"index_options": "docs",
"null_value": ""
},
"analyzed": {
"type": "string",
"index_analyzer": "eng_index_analyzer",
"search_analyzer": "eng_search_analyzer",
"null_value": "",
"include_in_all": "false"
}
}
}
}
当我查询name.analyzed字段时,它适用于至少包含两个字符的任何内容。例如,查询" Ra"会找到" Rafael"在名称字段中。但是,当我查询" R"或者" Rafael S",它不会返回任何结果。应该注意的是,在我们的查询中,空格被处理为" AND"运算符而不是" OR",所以基本上查询词的处理方式与 - " name包含[search term]"。
如何配置字段或分析器以便搜索单个字母?
答案 0 :(得分:0)
很难说没有看到查询,但根据discussion on the elastic forum如果您使用match_phrase_prefix查询,您可能会通过增加&#取得一些成功34; max_expansions"查询的属性,但会降低速度。
"max_expansions": 10000
该线程的另一个潜在解决方案是将operator
或default_operator
设置为"and"
(我认为您已经完成了)。