# How to compare two field values using query\_string in Elasticsearch

**URL:** <https://discuss.elastic.co/t/how-to-compare-two-field-values-using-query-string-in-elasticsearch/231713>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-monitoring\
**Created:** [May 8, 2020, 12:02pm UTC](https://discuss.elastic.co/t/how-to-compare-two-field-values-using-query-string-in-elasticsearch/231713 "2020-05-08T12:02:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srinivas\_Kondapally](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srinivas_kondapally/32/61014_2.png) [@Srinivas\_Kondapally](https://discuss.elastic.co/u/Srinivas_Kondapally)\
**Post date:** [May 8, 2020, 12:02pm UTC](https://discuss.elastic.co/t/how-to-compare-two-field-values-using-query-string-in-elasticsearch/231713/1 "2020-05-08T12:02:59Z")

</div>

I am using Elast Alert for Alerting System which queries ElasticSearch using REST API's for a certain interval of time. But I have a scenario that I need to compare two fields if the values of two fields get matches alert has to be triggered, but elast alert support filter option where we can write query string. I found using bool query along with the script query we can achieve it in elastic search, but how to write a query using query\_string for comparing two field values. Please help me out, thanks in advance

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 11, 2020, 6:30am UTC](https://discuss.elastic.co/t/how-to-compare-two-field-values-using-query-string-in-elasticsearch/231713/2 "2020-05-11T06:30:46Z")

</div>

I do not think you can do that using a query string. One way to do it might be through a scripted field but if you have the adata in the event you could also created a new field at index time that you could use directly.

---

<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:** [June 8, 2020, 6:30am UTC](https://discuss.elastic.co/t/how-to-compare-two-field-values-using-query-string-in-elasticsearch/231713/3 "2020-06-08T06:30:48Z")

</div>

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