Aggregations - eliranmoyal/elasticsearch-sql GitHub Wiki

##Elasticsearch-sql Aggregations

We support several elasticsearch aggregations ####Metrics

  • min
  • max
  • sum
  • count
  • avg
  • stats

####buckets

  1. 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
  1. 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)
  1. date histogram aggregation
  • put fieldName and interval
  • example SELECT online FROM online GROUP BY date_histogram(field='insert_time','interval'='1d')
  1. date range aggregation
  • put your fieldName and special intervals with format
  • example SELECT online FROM online GROUP BY date_range(field='insert_time','format'='yyyy-MM-dd' ,'2014-08-18','2014-08-17','now-8d','now-7d','now-6d','now')