Hey ES Wizards,
E.S. version 2.4.1
I am writing alarms and reports. I need to return multiple values from one Query DSL or wrap them somehow in order to pass both values into a report. Specifically, if I'm looking for Nginx Responses of "MISS" or "EXPIRED" (including the quotes), but I can't conglomerate the results, instead, I need the report to format as such:
Expires: {{payload.hits.total}} //only expires
Misses: {{payload.hits.total}} //only misses
Is this possible in one DSL Query? Is there a way I can nest them and alias the results so as to retrieve them in my report?
I can currently retrieve either misses or expires using:
GET /_search
{
"query": {
"template": {
"inline": { "match": { "NginxResponse": "{{query_string}}" }},
"params" : {
"query_string" : "\"EXPIRED\"",
"filter": {
"range": {
"@timestamp": {
"from": "now-7d"
}
}
}
}
}
}
}
Which returns:
{
"took": 25,
"timed_out": false,
"_shards": {
"total": 256,
"successful": 256,
"failed": 0
},
"hits": {
"total": 1198037,
"max_score": 7.3903913,
"hits": [.......
I can get the result from this and reference it in my reports as
{{payload.hits.total}}<!code>
From the code in my report shown as:
"input": {
"search": {
"request": {
"indices": [
"filebeat-*"
],
"body": {
"query": {
"template": {
"inline": {
"match": {
"NginxResponse": "{{query_string}}"
}
},
"params": {
"query_string": "\"MISS\"",
"filter": {
"range": {
"@timestamp": {
"from": "now-7d"
}
}
}
}
}
}
}
}
}
},
"condition": {
"script": {
"script": "payload.hits.total > 100"
}
}
Is there a way to modify this query so that I can pass in multiple variables that can be referenced in my report? This solution will also extend towards alarms that I'll generate once reporting is figured out.
Thanks in advance!
Edit: I may be barking up the wrong tree with the Query DSL, as I'm watching the Q&A following the 'Elasticsearch Query DSL' video and seeing that the Multi Search API https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-multi-search.html may be a better solution.
Does anyone have any solution architecture or best-approach suggestions? What I want to end up rolling up into the same report are three things; Misses, Expires & the ratio (Misses / (Misses + Expires)).