# How to pass the value of the query search to the message

**URL:** <https://discuss.elastic.co/t/how-to-pass-the-value-of-the-query-search-to-the-message/138314>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [July 3, 2018, 6:41am UTC](https://discuss.elastic.co/t/how-to-pass-the-value-of-the-query-search-to-the-message/138314 "2018-07-03T06:41:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![VietCong](https://avatars.discourse-cdn.com/v4/letter/v/e47774/32.png) [@VietCong](https://discuss.elastic.co/u/VietCong)\
**Post date:** [July 3, 2018, 6:41am UTC](https://discuss.elastic.co/t/how-to-pass-the-value-of-the-query-search-to-the-message/138314/1 "2018-07-03T06:41:07Z")

</div>

I have the watcher as below but I would like to pass the value of the "message" field to the alert message to Slack. Can someone please help? I have my watch syntax as below:

"text": "user minhhungvn107 attempted to execute {{ctx.input.search.request.body.query.bool.must.match.message}} command as root" ---\> this might not make sense at all since I dont have any experience with json but hopefully someone can help me understand how to do this and point me to the right direction of where I need to start to be able to write watches properly

```
{
  "trigger": {
    "schedule": {
      "interval": "30s"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "command_history"
        ],
        "types": [],
        "body": {
          "query": {
            "bool": {
              "must": {
                "match": {
                  "message": "sudo"
                }
              },
              "filter": {
                "range": {
                  "@timestamp": {
                    "from": "now-5m",
                    "to": "now"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gte": 1
      }
    }
  },
  "actions": {
    "notify-slack": {
      "slack": {
        "message": {
          "to": [
            "#slack-alert-from-siem"
          ],
          "text": "user minhhungvn107 attempted to execute ("#I want to pass the value of the command here") command as root"
        }
      }
    }
  }
}
```

---

<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:** [July 3, 2018, 8:20am UTC](https://discuss.elastic.co/t/how-to-pass-the-value-of-the-query-search-to-the-message/138314/2 "2018-07-03T08:20:01Z")

</div>

Take a look at the [examples repository](https://github.com/elastic/examples/tree/master/Alerting/Sample%20Watches), which contains a fair share of example watches. For example the `errors_in_logs` one is doing almost what you would like to do.

Side note: You can only access the response from a search, not the request itself.

--Alex

---

<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:** [July 31, 2018, 8:32am UTC](https://discuss.elastic.co/t/how-to-pass-the-value-of-the-query-search-to-the-message/138314/3 "2018-07-31T08:32:31Z")

</div>

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