I'm making an application that allows users to create reports on customers data, the user is able to add 0 or more grouping fields.
I'm using elastic 2.2.0, so if the user wants to group by day, then by age and then by sex the program sends the following query to elastic:
{
"aggs": {
"group_a": {
"date_histogram": {
"field": "transactionDate",
"interval": "day"
},
"aggs": {
"group_b": {
"terms": {
"field": "age"
}
},
"aggs": {
"group_c": {
"terms": {
"field": "sex"
}
}
}
}
}
}
}
I get this error:
{
"error": {
"root_cause": [
{
"type": "search_parse_exception",
"reason": "Could not find aggregator type [group_c] in [aggs]",
"line": 15,
"col": 11
}
]
}
}
How can I fix this?
If you want to nest group_c
into group_b
, you should use this json:
{
"aggs": {
"group_a": {
"date_histogram": {
"field": "transactionDate",
"interval": "day"
},
"aggs": {
"group_b": {
"terms": {
"field": "age"
},
"aggs": {
"group_c": {
"terms": {
"field": "sex"
}
}
}
}
}
}
}
}
Note that you were defining group_c
outside of group_b
, that was the error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With