elasticsearch - Elasticsearch:在关键字中搜索忽略大小写和重音(通过聚合)
问题描述
我可以像这样在索引上搜索特定关键字:
GET */_search/?
{
"query": {
"match_all": {}
},
"size": 0,
"aggs": {
"TECH.keyword": {
"terms": {
"field": "TECH.keyword",
"include": ".*mine.*",
"order": {
"_count": "desc"
},
"size": 20
}
}
}
}
使用此查询,我可以获取TECH.keyword
字段中包含“我的”的所有条目,按"_count": "desc"
. 所以,没关系。
实际的问题是索引可以包含,甚至mine
在Mine
字段中。我想全部归还。MINE
miné
TECH.keyword
有没有办法在关键字中搜索忽略大小写和重音?
当前映射为:
"TECH": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
解决方案
您应该能够使用normalizer
. 您不能使用analyzer
onkeyword
字段,但可以使用normalizer
. 它允许您使用lowercase
和asciifolding
。
https://www.elastic.co/guide/en/elasticsearch/reference/6.4/normalizer.html
PUT index { "settings": { "analysis": { "normalizer": { "my_normalizer": { "type": "custom", "char_filter": [], "filter": ["lowercase", "asciifolding"] } } } }, "mappings": { "_doc": { "properties": { "foo": { "type": "keyword", "normalizer": "my_normalizer" } } } } }
推荐阅读
- azure - Azure 免费试用帐户 VM 大小为灰色
- pyspark - 如何检查RDD是否包含pyspark中的列表元素?
- sql - 如何在 from_json Spark SQL 中从 double 转换为 int(NULL 输出)
- php - 将每个查询重定向到上层文件夹中的文件
- python - 解压 IEEE 754 浮点数
- html - 动态构建部分 Razor 视图 - 获取结束标记问题
- python - 为什么只绘制了一个情节?
- sql - 带有两个表和案例的 Oracle UPDATE
- rust - 自定义 concurrentMap 结构上的 RUST 借用问题
- javascript - 我可以在不使用 webpack 丑化的情况下缩小吗