I have an elastic query. I have a value corresponding to each website. I would like to group by website and sum all the value. Is it possible ? how can I do it ? Thanks
"size": 4000,
"query": {
"exists": {
"field": "site.website"
}
}
} ```
CodePudding user response:
The following query will group by website, and sum the value of the fields you want.
GET /<your-index>/_search
{
"size": 0,
"aggs": {
"websites": {
"terms": { "field": "site.website"},
"aggs": {
"total": {
"sum": {
"field": "<your field here>"
}
}
}
}
}
}
see here for more information: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html