Sridatta19
(Sridatta Pasumarthy)
April 10, 2022, 8:22am
1
I'm try to sort the results generated after performing terms, filter and sum aggregation. But I keep facing an error.
GET stats/_search
{
"size": 0,
"aggs": {
"group_by_names": {
"terms": {
"field": "playerid"
},
"aggs": {
"gender_filter": {
"filter": {
"term": {
"gender": "women"
}
},
"aggs": {
"sum_of_runs": {
"sum": {
"field": "runs"
}
},
"top_runs_by_player": {
"bucket_sort": {
"sort": [
"sum_of_runs"
]
}
}
}
}
}
}
}
}
The error which I'm facing is
{
"error" : {
"root_cause" : [ ],
"type" : "search_phase_execution_exception",
"reason" : "",
"phase" : "fetch",
"grouped" : true,
"failed_shards" : [ ],
"caused_by" : {
"type" : "class_cast_exception",
"reason" : "class org.elasticsearch.search.aggregations.bucket.filter.InternalFilter cannot be cast to class org.elasticsearch.search.aggregations.InternalMultiBucketAggregation (org.elasticsearch.search.aggregations.bucket.filter.InternalFilter and org.elasticsearch.search.aggregations.InternalMultiBucketAggregation are in unnamed module of loader 'app')"
}
},
"status" : 500
}
RabBit_BR
(andre.coelho)
April 10, 2022, 1:16pm
2
you can show a exemple of mapping and document?
Sridatta19
(Sridatta Pasumarthy)
April 10, 2022, 4:40pm
3
Thank you for responding;
Here is the mappings sample
{
"stats" : {
"aliases" : { },
"mappings" : {
"_meta" : {
"created_by" : "file-data-visualizer"
},
"properties" : {
"playerid" : {
"type" : "long"
},
"runs" : {
"type" : "long"
},
"gender" : {
"type" : "keyword"
},
"year" : {
"type" : "long"
}
}
},
"settings" : {
"index" : {
"routing" : {
"allocation" : {
"include" : {
"_tier_preference" : "data_content"
}
}
},
"provided_name" : "stats",
"uuid" : "lHJsdScXQSKe0m9ye16_Tg",
"version" : {
"created" : "7130499"
}
}
}
}
}
And this is the sample document
{
"playerid" : "53116",
"runs" : "65",
"gender" : "women"
}
}
RabBit_BR
(andre.coelho)
April 10, 2022, 5:04pm
4
I think the error is due to the depth of your query's aggregations.
I noticed that you use a filter, so I used it in the query and removed it from the aggregation.
I don't know if it's what you expected but the query returned results
{
"size": 0,
"query": {
"bool": {
"filter": [
{
"term": {
"gender": "women"
}
}
]
}
},
"aggs": {
"group_by_names": {
"terms": {
"field": "playerid"
},
"aggs": {
"sum_of_runs": {
"sum": {
"field": "runs"
}
},
"top_runs_by_player": {
"bucket_sort": {
"sort": [
{ "sum_of_runs": { "order": "asc" } }
]
}
}
}
}
}
}
1 Like
Sridatta19
(Sridatta Pasumarthy)
April 11, 2022, 5:02am
5
Thank you. This worked like a charm.
I was too caught up in filtering through aggregations that I forgot I could do this in a simple manner
system
(system)
Closed
May 9, 2022, 5:02am
6
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.