es系统:聚合分析报错: Text fields are not optimised for operations
Elasticsearch权威指南里的聚合分析报错: Text fields are not optimised for operations that require per-document field data like aggregations and sorting。GET /my_index/_search{"size": 0,"aggs": {"distinct_colors": {
·
Elasticsearch权威指南里的聚合分析报错: Text fields are not optimised for operations that require per-document field data like aggregations and sorting。
GET /my_index/_search
{
"size": 0,
"aggs": {
"distinct_colors": {
"cardinality": {
"field": "interests"
}
}
}
}
GET /my_index/_search
{
"size": 0,
"aggs": {
"distinct_colors": {
"cardinality": {
"field": "age"
}
}
}
}
在interests
上进行聚合会报错,而age
没问题。
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [xxxx] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
}
],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
因为interests
的type
是text
,而age
不是, text
或annotated_text
字段doc_values
默认为false
解决方案一:
简单理解,就是text
字段作为一个整体,默认没有索引.不过text
分词之后的keyword
是有索引的,因而可以对interests.keyword
进行聚合。
GET /my_index/_search
{
"size": 0,
"aggs": {
"distinct_colors": {
"cardinality": {
"field": "interests.keyword"
}
}
}
}
增加:keyword
解决方案二:
set fielddata=true
,不过不推荐
PUT employee/_mapping
{
"properties": {
"interests": {
"type": "text",
"fielddata": true
}
}
}
更多推荐
已为社区贡献15条内容
所有评论(0)