Skip to content

Instantly share code, notes, and snippets.

@jkbnerad
Created March 1, 2015 22:00
Show Gist options
  • Save jkbnerad/8e8f4de5c4ec1407d86a to your computer and use it in GitHub Desktop.
Save jkbnerad/8e8f4de5c4ec1407d86a to your computer and use it in GitHub Desktop.
Elasticsearch - aggregations
doc['exits'].value > 0) ? doc['orders'].value / doc['exits'].value : 0
{
"query": {
"filtered": {
"query": {"match_all": {}},
"filter": {"range": {
"date": {
"from": "2014-03-01",
"to": "2015-02-28"
}
}}
}
},
"aggs": {
"counts" : {
"terms": {
"field": "variant",
"order": {
"exits": "desc"
}
},
"aggs" : {
"exits" : {
"sum" : {"field":"exits"}
},
"orders" : {
"sum" : {"field" : "orders"}
},
"rate" : {
"avg" : {"script" : "agg_rate"}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment