the way to go here would be a script transform allowing you to change or add something to the existing payload. In this case you would probably have a list of maps, where each map contains the index/fieldname data of each document. Then you can walk through it easily in a mustache template.
If I wish to do this on an aggregation, is it the same, script tranform?
I am trying to create an html table with each backend name and it's doc_count for my corresponding query
Here is the input
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"ccwhaproxy-*"
],
"types": [],
"body": {
"query": {
"bool": {
"must": [
{
"term": {
"status_code": "200"
}
},
{
"range": {
"@timestamp": {
"gt": "now-10m/m",
"lte": "now"
}
}
}
]
}
},
"_source": "backend_name",
"aggs": {
"unique": {
"terms": {
"field": "backend_name.keyword"
}
}
}
}
}
}
In my actions, I have an email, body as html
{
"profile": "standard",
"attachments": {
"attached_data": {
"data": {
"format": "json"
}
}
},
"from": "noreply@xxx.com",
"priority": "high",
"to": [
"xxx@xxx.com"
],
"subject": "503 Service Unavailable Alert - CCWHaproxy",
"body": {
` "html": "<head> <h1>503 Backend Counts</h1> </head><body> <table> <tr><th>Backend Name</th><th>Count</th></tr><tr><td>{{#ctx.payload.aggregations.unique.buckets}}{{key}}{{/ctx.payload.aggregations.unique.buckets}}</td><td>{{#ctx.payload.aggregations.unique.buckets}}{{doc_count}}{{/ctx.payload.aggregations.unique.buckets}}</td></tr></table></body>"`
}
}
But this is printing all the keys concatenated in one cell and all the values concatenated in another cell
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.