Sum greater than some amount group by Phone


(Nikhil Nambiar) #1

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


(Alexander Reelsen) #2

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


(Nikhil Nambiar) #3

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"}
       }
    }
  }

}

(system) #4

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