Skip to content

Instantly share code, notes, and snippets.

@yinchunxiang
Created June 30, 2014 09:58
Show Gist options
  • Save yinchunxiang/b887fdc025bac87eafc6 to your computer and use it in GitHub Desktop.
Save yinchunxiang/b887fdc025bac87eafc6 to your computer and use it in GitHub Desktop.
# SELECT COUNT(*) from bank GROUP BY state ORDER BY COUNT(*) DESC
curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
{
"size": 0,
"aggs": {
"group_by_state": {
"terms": {
"field": "state"
}
}
}
}'
# This example demonstrates how we can group by age brackets (ages 20-29, 30-29, and 40-49),
# then by gender, and then finally get the average account balance, per age bracket, per gender
curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
{
"size": 0,
"aggs": {
"group_by_state": {
"terms": {
"field": "state",
"order": {
"average_balance": "desc"
}
},
"aggs": {
"average_balance": {
"avg": {
"field": "balance"
}
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment