Last active
August 29, 2015 14:21
-
-
Save orweinberger/48c76a6686527a2e5277 to your computer and use it in GitHub Desktop.
Elasticsearch query examples
This file contains 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
/* Simple query */ | |
{ | |
"query": { | |
"bool": { | |
"must": { | |
"match": { | |
"host": "10.168.233.28" | |
} | |
} | |
} | |
} | |
} | |
/* Multiple conditions */ | |
{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"match": { | |
"host": "10.168.233.28" | |
} | |
}, | |
{ | |
"match": { | |
"severity_label": "Notice" | |
} | |
} | |
] | |
} | |
} | |
} | |
/* Simple aggregation */ | |
{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"match": { | |
"host": "10.168.233.28" | |
} | |
}, | |
{ | |
"match": { | |
"severity_label": "Notice" | |
} | |
} | |
] | |
} | |
}, | |
"aggs": { | |
"severity_agg": { | |
"terms": { | |
"field": "severity_label" | |
} | |
} | |
} | |
} | |
/* Unique count (cardinality) */ | |
{ | |
"size": 1, | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"match": { | |
"severity_label": "Notice" | |
} | |
} | |
] | |
} | |
}, | |
"aggs": { | |
"severity_agg": { | |
"cardinality": { | |
"field": "host" | |
} | |
} | |
} | |
} | |
/* Multiple aggregations */ | |
{ | |
"size": 1, | |
"query": { | |
"match_all": {} | |
}, | |
"aggs": { | |
"day": { | |
"date_histogram": { | |
"field": "@timestamp", | |
"interval": "day" | |
}, | |
"aggs": { | |
"severity": { | |
"terms": { | |
"field": "severity" | |
}, | |
"aggs": { | |
"host": { | |
"cardinality": { | |
"field": "host" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment