Hi to all,
I want to get the Elasticsearch translation of SQL "Group by & sum field" anyone can help me?
thanks
Ivan
Hi to all,
I want to get the Elasticsearch translation of SQL "Group by & sum field" anyone can help me?
thanks
Ivan
You can run a first level of aggregation (let say a Terms aggregation) and the add a sub sum aggregation.
Like:
{
"aggs": {
"by_xxx": {
"terms": {
"field": "xxx"
},
"aggs": {
"do_a_sum_on_field_yyy": {
"sum": {
"field": "yyy"
}
}
}
}
}
}
Written from the top of my head so might be buggy though.
HTH
It works Thank u!!
Just another question is it possible order by do_a_sum_on_field_yyy ?
I don't think so. As the first level of the tree will be by term.
David
Thanks
© 2020. All Rights Reserved - Elasticsearch
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant logo are trademarks of the Apache Software Foundation in the United States and/or other countries.