Watcher does not show results in the mail message

Hello good day, I have a problem with the action of a watch, it does not show me the results in the email message it sends, I use {{ctx.payload.hits.total}} and also {{ctx.payload.aggregations.heartbeat_count}} to show the results to the email, but nothing appears, it does not show it here is the code:

{
  "trigger": {
    "schedule": {
      "daily": {
        "at": [
          "14:00"
        ]
      }
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "heartbeat*"
        ],
        "rest_total_hits_as_int": true,
        "body": {
          "size": 0,
          "query": {
            "bool": {
              "filter": [
                {
                  "range": {
                    "@timestamp": {
                      "gte": "now-1d/d",
                      "lt": "now/d"
                    }
                  }
                }
              ]
            }
          },
          "aggs": {
            "heartbeat_count": {
              "value_count": {
                "field": "_index"
              }
            }
          }
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gte": 10
      }
    }
  },
  "actions": {
    "email_1": {
      "email": {
        "profile": "standard",
        "attach_data": {
          "format": "yaml"
        },
        "to": [
          "victor.vera@megadvantage.com",
          "juan.jaramillo@megadvantage.com",
          "andres.molinac.pr@etb.com.co",
          "juan.ariasp1.pr@etb.com.co"
        ],
        "bcc": [
          "juancho.jaramillo16@gmail.com"
        ],
        "subject": "{{ctx.metadata.name}}",
        "body": {
          "text": """Buen dia, 

 ⚠La herramienta de monitoreo a funcionado correctamente en las ultimas  24 horas  
 
 {{ctx.payload.hits.total}} {{ctx.payload.result}} 
 
{{ctx.payload.aggregations.heartbeat_count}}  {{ctx.payload.aggregations.heartbeat_count}}
 
 Estado: UP🟢 

 🕧Hora: {{ctx.payload.time_triggered}}  {{ctx.result.execution_time}}

 Área: Networking 
 
🔔Mensaje Alerta: Por favor no responder a este mensaje 

 """
        }
      }
    }
  },
  "transform": {
    "script": {
      "source": "return [ 'time_triggered': Instant.ofEpochMilli(ctx.trigger.triggered_time.getMillis()).atZone(ZoneId.of('America/Bogota')).format(DateTimeFormatter.ofPattern('YYYY-MM-dd HH:mm:ss')) ];",
      "lang": "painless"
    }
  }
}

this is the result:


{
  "watch_id": "_inlined_",
  "node": "ELuSGxpSRICZb2ZHJp4paA",
  "state": "executed",
  "user": "elastic",
  "status": {
    "state": {
      "active": true,
      "timestamp": "2021-04-23T15:15:08.291Z"
    },
    "last_checked": "2021-04-23T15:15:08.292Z",
    "last_met_condition": "2021-04-23T15:15:08.292Z",
    "actions": {
      "email_1": {
        "ack": {
          "timestamp": "2021-04-23T15:15:08.292Z",
          "state": "ackable"
        },
        "last_execution": {
          "timestamp": "2021-04-23T15:15:08.292Z",
          "successful": true
        },
        "last_successful_execution": {
          "timestamp": "2021-04-23T15:15:08.292Z",
          "successful": true
        }
      }
    },
    "execution_state": "executed",
    "version": -1
  },
  "trigger_event": {
    "type": "manual",
    "triggered_time": "2021-04-23T15:15:08.292Z",
    "manual": {
      "schedule": {
        "scheduled_time": "2021-04-23T15:15:08.292Z"
      }
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "heartbeat*"
        ],
        "rest_total_hits_as_int": true,
        "body": {
          "size": 0,
          "query": {
            "bool": {
              "filter": [
                {
                  "range": {
                    "@timestamp": {
                      "gte": "now-1d/d",
                      "lt": "now/d"
                    }
                  }
                }
              ]
            }
          },
          "aggs": {
            "heartbeat_count": {
              "value_count": {
                "field": "_index"
              }
            }
          }
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gte": 10
      }
    }
  },
  "metadata": {
    "name": "Estado herramienta monitoreo",
    "xpack": {
      "type": "json"
    }
  },
  "result": {
    "execution_time": "2021-04-23T15:15:08.292Z",
    "execution_duration": 25,
    "input": {
      "type": "search",
      "status": "success",
      "payload": {
        "_shards": {
          "total": 8,
          "failed": 0,
          "successful": 8,
          "skipped": 0
        },
        "hits": {
          "hits": [],
          "total": 10000,
          "max_score": null
        },
        "took": 22,
        "timed_out": false,
        "aggregations": {
          "heartbeat_count": {
            "value": 82079
          }
        }
      },
      "search": {
        "request": {
          "search_type": "query_then_fetch",
          "indices": [
            "heartbeat*"
          ],
          "rest_total_hits_as_int": true,
          "body": {
            "size": 0,
            "query": {
              "bool": {
                "filter": [
                  {
                    "range": {
                      "@timestamp": {
                        "gte": "now-1d/d",
                        "lt": "now/d"
                      }
                    }
                  }
                ]
              }
            },
            "aggs": {
              "heartbeat_count": {
                "value_count": {
                  "field": "_index"
                }
              }
            }
          }
        }
      }
    },
    "condition": {
      "type": "compare",
      "status": "success",
      "met": true,
      "compare": {
        "resolved_values": {
          "ctx.payload.hits.total": 10000
        }
      }
    },
    "transform": {
      "type": "script",
      "status": "success",
      "payload": {
        "time_triggered": "2021-04-23 10:15:08"
      }
    },
    "actions": [
      {
        "id": "email_1",
        "type": "email",
        "status": "simulated",
        "email": {
          "message": {
            "id": "email_1__inlined__c2715d98-3714-45ef-808c-d5c9b10762a3-2021-04-23T15:15:08.292507Z_26863",
            "sent_date": "2021-04-23T15:15:08.318001Z",
            "to": [
              "victor.vera@megadvantage.com",
              "juan.jaramillo@megadvantage.com",
              "andres.molinac.pr@etb.com.co",
              "juan.ariasp1.pr@etb.com.co"
            ],
            "bcc": [
              "juancho.jaramillo16@gmail.com"
            ],
            "subject": "Estado herramienta monitoreo",
            "body": {
              "text": "Buen dia, \n\n ⚠La herramienta de monitoreo a funcionado correctamente en las ultimas  24 horas  \n \n   \n \n  \n \n Estado: UP🟢 \n\n 🕧Hora: 2021-04-23 10:15:08  \n\n Área: Networking \n \n🔔Mensaje Alerta: Por favor no responder a este mensaje \n\n "
            }
          }
        }
      }
    ]
  },
  "messages": []
}

For anyone looking answer is here

Hello stephenb,
I am trying to achieve something similar in my below post:

Will you be able to help me out?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.