进行下面语句聚合查询
GET my_test_index/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"Type": "2" //子文档条件
}
},
{
"has_parent": {
"parent_type": "parent_table", //父文档
"query": {
"match": {
"number": "5203021066009201800035" //父文档条件
}
}
}
}
]
}
},
"aggs":{
"type_count":{
"cardinality":{
"field":"Type"
}
}
}
}
执行上述聚合查询报一下错误
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [Type] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "my_test_index",
"node": "yLtKrjnoSsiLSArX-y9DaQ",
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [Type] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
}
],
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [Type] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [Type] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
}
},
"status": 400
}
提示fielddata=true未开启 因为ElasticSearch中默认fielddata默认是false的
需要做的是:开启聚合字段fielddata=true
PUT my_test_index/_mapping/_doc
{
"properties": {
"Type": {
"type": "text",
"fielddata": true
}
}
}