# Watcher - issue with search templates

**URL:** https://discuss.elastic.co/t/watcher-issue-with-search-templates/106655
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [November 7, 2017, 9:26am UTC](https://discuss.elastic.co/t/watcher-issue-with-search-templates/106655 "2017-11-07T09:26:26Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Mariusz\_Zyla](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@Mariusz\_Zyla](https://discuss.elastic.co/u/Mariusz_Zyla)
#### Post date: [November 7, 2017, 9:26am UTC](https://discuss.elastic.co/t/watcher-issue-with-search-templates/106655/1 "2017-11-07T09:26:26Z")

</div>

Hi,

I'm trying to create a watcher with a chain input type as follow:

```
"input": {
    "chain": {
      "inputs": [
        {
          "constants": {
            "simple": {
              "host_name": "aassddcc.localdomain"
            }
          }
        },
        {
          "host_hits_check": {
            "search": {
              "request": {
                "search_type": "query_then_fetch",
                "indices": [
                  "metric*"
                ],
                "types": [],
                "template": {
                  "file": "host_hits_template",
                  "lang": "mustache",
                  "params": {
                    "host": "{{ctx.payload.constants.host_name}}"
                  }
                }
              }
            }
          }
        }
      ]
    }
  }

```

But in this case the value passed to the template is the exact value, the value is not substitute by the host\_name from the input constants:

```
"host_hits_check": {
          "type": "search",
          "status": "success",
          "payload": {
            "_shards": {
              "total": 25,
              "failed": 0,
              "successful": 25,
              "skipped": 0
            },
            "hits": {
              "hits": [],
              "total": 0,
              "max_score": 0
            },
            "took": 10,
            "timed_out": false
          },
          "search": {
            "request": {
              "search_type": "query_then_fetch",
              "indices": [
                "metric*"
              ],
              "types": [],
              "body": {
                "size": 0,
                "query": {
                  "bool": {
                    "must": [
                      {
                        "range": {
                          "@timestamp": {
                            "gt": "now-2m"
                          }
                        }
                      },
                      {
                        "term": {
                          "host.keyword": "{{ctx.payload.constants.host_name}}"
                        }
                      }
                    ]
                  }
                },
                "sort": [
                  {
                    "@timestamp": {
                      "order": "desc"
                    }
                  }
                ]
              },
              "template": {
                "file": "host_hits_template",
                "lang": "mustache",
                "params": {
                  "host": "{{ctx.payload.constants.host_name}}"
                }
              }
            }
          }
        }

```

In other cases it works properly. For instance when I use a query instead of templates or I use a HTTP input type. The problem is only with passing a value to the parameter of the template.

I use the version 5.6.3 of Elasticsearch and X-Pack.

Do you have any idea how to deal with it ?

Thanks in advance,  
Mariusz

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [November 7, 2017, 12:40pm UTC](https://discuss.elastic.co/t/watcher-issue-with-search-templates/106655/2 "2017-11-07T12:40:53Z")

</div>

hey,

what do you mean with `in other cases` in your reply? Can you elaborate what works?

I havent checked yet, but I'd assume, that resolving fields in the `template` part of a query does not work. This only works in the `body` part.

--Alex

---

<div class="post-metadata">

### Author: ![Mariusz\_Zyla](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@Mariusz\_Zyla](https://discuss.elastic.co/u/Mariusz_Zyla)
#### Post date: [November 7, 2017, 1:08pm UTC](https://discuss.elastic.co/t/watcher-issue-with-search-templates/106655/3 "2017-11-07T13:08:05Z")

</div>

Thanks Alex,  
it works with the other input types. For example:

**HTTP Input:**

```
"http_action": {
            "http": {
              "request": {
                "scheme": "http",
                "host": "localhost",
                "port": 9200,
                "method": "get",
                "path": "{{ctx.payload.constants.path}}",
                "params": {},
                "headers": {}
              }
            }
          }

```

**Search Input (query instead of template):**

```
"host_hits_check": {
            "search": {
              "request": {
                "search_type": "query_then_fetch",
                "indices": [
                  "metric*"
                ],
                "types": [],
                "body": {
                  "query": {
                    "match": {
                      "host": "{{ctx.payload.constants.host_name}}"
                    }
                  }
                }
              }
            }
          }

```

It seems that your assumption is right that the resolving fields functionality does not work with the templates.

Mariusz

---

<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: [December 5, 2017, 1:08pm UTC](https://discuss.elastic.co/t/watcher-issue-with-search-templates/106655/4 "2017-12-05T13:08:05Z")

</div>

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