elasticsearch - Elastic search find sum of two fields in single query -
i have requirement of find sum of 2 fields in single query. have managed find sum of 1 field, facing difficulty add 2 aggression in single query.
my json following way
{ "_index": "outboxprov1", "_type": "message", "_id": "jxpdpnefskko-hij3t9m4w", "_score": 1, "_source": { "team_id": "1fa86701af05a863f59dd0f4b6546b32", "created_user": "1a9d05586a8dc3f29b4c8147997391f9", "created_ip": "192.168.2.245", "folder": 1, "post_count": 5, "sent": 3, "failed": 2, "status": 6, "message_date": "2014-08-20t14:30z", "created_date": "2014-06-27t04:34:30.885z" } }
my search query
{ "query": { "filtered": { "query": { "match": { "team_id": { "query": "1fa86701af05a863f59dd0f4b6546b32" } } }, "filter": { "and": [ { "term": { "status": "6" } } ] } } }, "aggs": { "intraday_return": { "sum": { "field": "sent" } } }, "aggs": { "intraday_return": { "sum": { "field": "failed" } } } }
how put 2 aggression in 1 query? please me solve issue. thank you
you can compute sum using script
example:
{ "size": 0, "aggregations": { "age_ranges": { "range": { "script": "datetime.now().year - doc[\"birthdate\"].date.year", "ranges": [ { "from": 22, "to": 25 } ] } } } }
your query should contain "script" : "doc['sent'].value+doc['failed'].value"
Comments
Post a Comment