Elasticsearch中如何选择合适的分析器
How to choose appropriate analyzer in Elasticsearch
我有一个要求,我需要根据以下条件执行搜索。
1]不区分大小写的匹配
2]特殊字符匹配
3]部分匹配
我使用的"ngram filter"如下,满足以上需求
但是,我将索引一个非常大的数据,其中包含 "comments"、"descriptions" 等字段,长度可能高达 150 个单词。
从网上的参考资料来看,我认为使用 "ngram" 过滤器会导致磁盘 space 使用率过高。
是否有任何替代方案可以满足上述要求
{
"template": "*",
"settings": {
"analysis": {
"filter": {
"ngram_filter": {
"type": "ngram",
"min_gram": 1,
"max_gram": 25
}
},
"analyzer": {
"case_insensitive": {
"tokenizer": "whitespace",
"filter": [
"ngram_filter",
"lowercase"
]
},
"search_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": "lowercase"
}
}
}
},
"mappings": {
"incidents": {
"dynamic_templates": [
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "string",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "case_insensitive",
"search_analyzer": "search_analyzer"
}
}
}
]
}
}
}
谢谢!
我想搜索性能也很关键,在这种情况下你必须使用 ngrams。但是您可以尝试减少最小的 ngram 大小。例如,如果可以跳过一个或两个字母的匹配,则可以将 min_gram
设置为 3
或更大。它会稍微减少磁盘使用量。
也可以使用 wildcard
或 query_string
查询进行部分匹配。第一个区分大小写,第二个不区分大小写。在这种情况下,您不会有磁盘使用开销,但会显着降低性能。
这通常是搜索速度和磁盘使用率之间的权衡。通常最好进行适当的预索引(n-gram 方法)以达到所需的性能
我有一个要求,我需要根据以下条件执行搜索。
1]不区分大小写的匹配
2]特殊字符匹配
3]部分匹配
我使用的"ngram filter"如下,满足以上需求 但是,我将索引一个非常大的数据,其中包含 "comments"、"descriptions" 等字段,长度可能高达 150 个单词。 从网上的参考资料来看,我认为使用 "ngram" 过滤器会导致磁盘 space 使用率过高。 是否有任何替代方案可以满足上述要求
{
"template": "*",
"settings": {
"analysis": {
"filter": {
"ngram_filter": {
"type": "ngram",
"min_gram": 1,
"max_gram": 25
}
},
"analyzer": {
"case_insensitive": {
"tokenizer": "whitespace",
"filter": [
"ngram_filter",
"lowercase"
]
},
"search_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": "lowercase"
}
}
}
},
"mappings": {
"incidents": {
"dynamic_templates": [
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "string",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "case_insensitive",
"search_analyzer": "search_analyzer"
}
}
}
]
}
}
}
谢谢!
我想搜索性能也很关键,在这种情况下你必须使用 ngrams。但是您可以尝试减少最小的 ngram 大小。例如,如果可以跳过一个或两个字母的匹配,则可以将 min_gram
设置为 3
或更大。它会稍微减少磁盘使用量。
也可以使用 wildcard
或 query_string
查询进行部分匹配。第一个区分大小写,第二个不区分大小写。在这种情况下,您不会有磁盘使用开销,但会显着降低性能。
这通常是搜索速度和磁盘使用率之间的权衡。通常最好进行适当的预索引(n-gram 方法)以达到所需的性能