Sum greater than some amount group by Phone

I have a json

{
phone : "phone numbers"
amount :"amount of call"
uts:"date in text"
}

how can I achieve a query which will give me sum of amount for individual phone and filter out those phone whose sum of amount is greater than some amount

you can use a range query to filter to an amount and then use the sum aggregation

Note that in case of the above being within an array, you need to take a look at the nested datatype

Can anyone help me, where I am making mistake. My target is to get sum of amount respectively to phone number between the specified date range

{

"query":{
	"range":{
    	"uts":{
          "gte":"2018-08-01",
          "lte":"2018-08-31",
          "format":"yyyy-MM-dd"
        }
    }
},
"aggs":{
  "group_by_phone":{
	"filter":{
  "terms":{
      "field":"phone.keyword"
    }
 }
},
"aggs":{
	"total_sum":{
    	"sum":{"field":"amount"}
       }
    }
  }

}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.