# Dynamic Variable in Query - Match Phrase

**URL:** <https://discuss.elastic.co/t/dynamic-variable-in-query-match-phrase/154263>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [October 26, 2018, 11:41pm UTC](https://discuss.elastic.co/t/dynamic-variable-in-query-match-phrase/154263 "2018-10-26T23:41:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lochinvar](https://avatars.discourse-cdn.com/v4/letter/l/977dab/32.png) [@lochinvar](https://discuss.elastic.co/u/lochinvar)\
**Post date:** [October 26, 2018, 11:41pm UTC](https://discuss.elastic.co/t/dynamic-variable-in-query-match-phrase/154263/1 "2018-10-26T23:41:31Z")

</div>

I was using kibana watcher for monitoring and alerts. In Watcher i have used the user defined variable in the condition script(painless script) and it is working fine. Is there any ways i can use a variable in http request query using user defined variable for a match phrase.

**Sample:**

"query": {  
"match" : {  
"message" : "this is a test"  
}  
}  
Expectation:  
"query": {  
"match" : {  
"message" : user defined variable  
}  
}

---

<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 2, 2018, 9:14am UTC](https://discuss.elastic.co/t/dynamic-variable-in-query-match-phrase/154263/2 "2018-11-02T09:14:51Z")

</div>

Hey,

I am not sure if you are referring to a HTTP request or a search request. However you can use variables from the watch metadata like `{{ctx.metadata.my_metadata_variable}}`.

If you share your full watch, taking a closer look might be easier.

--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:** [November 30, 2018, 9:14am UTC](https://discuss.elastic.co/t/dynamic-variable-in-query-match-phrase/154263/3 "2018-11-30T09:14:51Z")

</div>

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