Last active
August 29, 2015 14:18
-
-
Save jakubkulhan/3f09a719257882173ec2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $q = [ | |
| "query" => ["filtered" => [ | |
| "filter" => ["range" => [ | |
| "created" => ["gte" => "-31 days"], | |
| ]], | |
| ]], | |
| "aggs" => [ | |
| "by_date" => ["date_histogram" => [ | |
| "field" => "created", | |
| "interval" => "1d", | |
| "aggs" => [ | |
| "by_severity" => ["filters" => [ | |
| "filters" => [ | |
| "error" => ["term" => ["severity" => 1]], | |
| "warning" => ["term" => ["severity" => 2]], | |
| // no need for total, by_date buckets already have doc_count == total | |
| // "total" => ["match_all" => []], | |
| ], | |
| ]], | |
| ], | |
| ]] | |
| ] | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| DATE(created), | |
| COUNT(*) total, | |
| SUM(IF(severity = 1, 1, 0)) errors, | |
| SUM(IF(severity = 2, 1, 0)) warnings | |
| FROM t | |
| WHERE created >= NOW()-INTERVAL 31 DAY | |
| GROUP BY DATE(created) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment