Elasticsearch关键字以及小写和聚合 [英] Elasticsearch keyword and lowercase and aggregation
问题描述
我以前用映射关键字存储了一些字段。但是,它们是区分大小写的。
I have previously stored some fields with the mapping "keyword". But, they are case senstive.
要解决此问题,可以使用分析仪,例如
To solve this, it is possible to use an analyzer, such as
{
"index": {
"analysis": {
"analyzer": {
"keyword_lowercase": {
"tokenizer": "keyword",
"filter": [
"lowercase"
]
}
}
}
}
}
有映射
{
"properties": {
"field": {
"type": "string",
"analyzer": "keyword_lowercase"
}
}
}
按条件聚合不起作用。
原因:java.lang.IllegalArgumentException:默认情况下,文本字段的字段数据处于禁用状态。在[a]上设置fielddata = true,以通过反转取反的索引将字段数据加载到内存中。但是请注意,这可能会占用大量内存。
Caused by: java.lang.IllegalArgumentException: Fielddata is disabled on text fields by default. Set fielddata=true on [a] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory.
它适用于映射type = keyword,但是type = keyword不允许分析器
It works on mapping type=keyword, but type=keyword does not allow analyzer it seems.
如何将其索引为小写关键字,但仍然可以在不设置fielddata = true的情况下使用聚合?
推荐答案
如果您使用的是ES 5.2或更高版本,则现在可以使用 规范化器
s for 关键字
字段。只需像这样声明索引设置和映射就可以了
If you're using ES 5.2 or above, you can now leverage normalizer
s for keyword
fields. Simply declare your index settings and mappings like this and you're good to go
PUT index
{
"settings": {
"analysis": {
"normalizer": {
"keyword_lowercase": {
"type": "custom",
"filter": ["lowercase"]
}
}
}
},
"mappings": {
"type": {
"properties": {
"field": {
"type": "keyword",
"normalizer": "keyword_lowercase"
}
}
}
}
}
这篇关于Elasticsearch关键字以及小写和聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!