-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Aggregations
Caleb Ott edited this page Oct 12, 2015
·
19 revisions
##Elasticsearch-sql Aggregations
We support several elasticsearch aggregations ####Metrics
- min
- max
- sum
- count
- avg
- stats
- percentiles
- extended_stats
just use like this on numeric fields:SELECT stats(age) FROM account
####buckets
- terms aggregation
- Use group by fieldName , you can also put multiple fields
- examples
SELECT COUNT(*) FROM account GROUP BY gender
SELECT COUNT(*) FROM account GROUP BY gender, age
- multiple aggregations
- Use group by (fieldName),(fieldName, fieldName)
- Each field in parenthesis is given its own aggregation
- Each list of fields in parenthesis is its own aggregation with sub aggregations
- examples
SELECT * FROM account GROUP BY (gender),(age)
SELECT * FROM account GROUP BY (gender, state),(age)
SELECT * FROM account GROUP BY (gender, state, age),(state),(age)
- range aggregation
- put fieldName followed by your ranges
- example , if you want to range: age with groups 20-25,25-30,30-35,35-40
SELECT COUNT(age) FROM bank GROUP BY range(age, 20,25,30,35,40)
- date histogram aggregation
- put fieldName and interval
- alias is optional
- example
SELECT online FROM online GROUP BY date_histogram(field='insert_time','interval'='1d','alias'='yourAlias')
- date range aggregation
- put your fieldName and special intervals with format
- alias is optional
- example
SELECT online FROM online GROUP BY date_range('alias'='yourAlias',field='insert_time','format'='yyyy-MM-dd' ,'2014-08-18','2014-08-17','now-8d','now-7d','now-6d','now')