Combining Painless and Mustache

I thought mustache is used for display purposes only. It has no effect on a search.
The aggregation used gives a multi-level aggregation results so it outputs some result

    "send_email": {
      "email": {
        "profile": "standard",
        "from": "example@example.com",
        "to": [
          "example@example.com"
        ],
        "subject": "Failed Login Exceeding",
        "body": {
          "text": """Failed Login Exceeding
{{#ctx.payload.aggregations.server_name.buckets}}
{{key.host_name}}
{{#events.buckets}}
    Time: {{key_as_string}}
    {{#user_name.buckets}}
          {{key}}    Count={{doc_count}}
    {{/user_name.buckets}}
{{/events.buckets}}

{{/ctx.payload.aggregations.server_name.buckets}}"""
        }
      }
    }

Output of email body is like this

           "body": {
              "text": "Failed Login Exceeding\nelk1\n    Time: 2022-02-10T04:42:00.000Z\n          guest    Count=3\n    Time: 2022-02-10T04:43:00.000Z\n          guest    Count=2\n\n"
            }

Looks like

Failed Login Exceeding
    elk1    
        Time: 2022-02-10T04:42:00.000Z
             guest    Count=3
        Time: 2022-02-10T04:43:00.000Z
             guest    Count=2