# Watcher does not show results in the mail message

**URL:** https://discuss.elastic.co/t/watcher-does-not-show-results-in-the-mail-message/271106
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [April 23, 2021, 3:16pm UTC](https://discuss.elastic.co/t/watcher-does-not-show-results-in-the-mail-message/271106 "2021-04-23T15:16:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Juan\_David\_Jaramillo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/juan_david_jaramillo/32/76831_2.png) [@Juan\_David\_Jaramillo](https://discuss.elastic.co/u/Juan_David_Jaramillo)
#### Post date: [April 23, 2021, 3:16pm UTC](https://discuss.elastic.co/t/watcher-does-not-show-results-in-the-mail-message/271106/1 "2021-04-23T15:16:29Z")

</div>

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:

```auto
{
  "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:

```auto

{
  "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": []
}

```

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [April 24, 2021, 7:08pm UTC](https://discuss.elastic.co/t/watcher-does-not-show-results-in-the-mail-message/271106/2 "2021-04-24T19:08:50Z")

</div>

For anyone looking answer is [here](https://discuss.elastic.co/t/watcher-that-counts-the-documents-that-arrive-to-an-index-in-kibana/270609/45)

---

<div class="post-metadata">

### Author: ![Patr123](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@Patr123](https://discuss.elastic.co/u/Patr123)
#### Post date: [April 26, 2021, 2:59am UTC](https://discuss.elastic.co/t/watcher-does-not-show-results-in-the-mail-message/271106/3 "2021-04-26T02:59:15Z")

</div>

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

> [@How to include the ctx.payload.value in the email text for watcher alert?](https://discuss.elastic.co/t/how-to-include-the-ctx-payload-value-in-the-email-text-for-watcher-alert/269655):
>
> Hello All, I am trying to create a watcher alert for the servers that communicated to elastic in last 48 hrs but not in last 35 mins. I want to include the ctx.payload.value result in my email text but all I am getting is a blank value. My watcher json file looks like: { "input": { "search": { "request": { "search\_type": "query\_then\_fetch", "indices": ["metricbeat123-\*"], "rest\_total\_…

Will you be able to help me out?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 24, 2021, 3:00am UTC](https://discuss.elastic.co/t/watcher-does-not-show-results-in-the-mail-message/271106/4 "2021-05-24T03:00:08Z")

</div>

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