Hi everybody,
I'm running Elastic Stack 8.5 and I have configured Kibana Alerts to send message into Slack, when certain DSL query is matched. To include some fields of matched documents I've used the following Mustache template:
- Amount of responses got per {{params.timeWindowSize}}{{params.timeWindowUnit}}: {{context.value}}
- Timestamp: {{context.date}}
Request: {{context.hits.0._source.ingress_controller_logs.request}}
User Agent: {{context.hits.0._source.ingress_controller_logs.user_agent}}
Response: {{context.hits.0._source.ingress_controller_logs.status}}
Response Time: {{context.hits.0._source.ingress_controller_logs.request_time}}
The problem happens when there's multiple documents matched by the query. Only the data from first matched document occurs in the message. This is fully logical, because all further hits should be referenced with a proper array index value, like so:
Request: {{context.hits.1._source.ingress_controller_logs.request}}
and so on.
My question is the following: is there any way to use some sort of iterator where the array index should be, so it would iterate over index dynamically and return all values from all array elements. For example:
Request: {{context.hits.@._source.ingress_controller_logs.request}}
So, if the three documents would match by the query, it would look like it had this formatting:
Request: {{context.hits.0._source.ingress_controller_logs.request}}
User Agent: {{context.hits.0._source.ingress_controller_logs.user_agent}}
Response: {{context.hits.0._source.ingress_controller_logs.status}}
Response Time: {{context.hits.0._source.ingress_controller_logs.request_time}}
Request: {{context.hits.1._source.ingress_controller_logs.request}}
User Agent: {{context.hits.1._source.ingress_controller_logs.user_agent}}
Response: {{context.hits.1._source.ingress_controller_logs.status}}
Response Time: {{context.hits.1._source.ingress_controller_logs.request_time}}
Request: {{context.hits.2._source.ingress_controller_logs.request}}
User Agent: {{context.hits.2._source.ingress_controller_logs.user_agent}}
Response: {{context.hits.2._source.ingress_controller_logs.status}}
Response Time: {{context.hits.2._source.ingress_controller_logs.request_time}}
Any advice is much appreciated.
Thanks in advance.