# Check if index value is substring of input string

**URL:** <https://discuss.elastic.co/t/check-if-index-value-is-substring-of-input-string/314191>\
**Category:** Elasticsearch\
**Created:** [September 12, 2022, 12:03pm UTC](https://discuss.elastic.co/t/check-if-index-value-is-substring-of-input-string/314191 "2022-09-12T12:03:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahulkothanath](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahulkothanath/32/99122_2.png) [@rahulkothanath](https://discuss.elastic.co/u/rahulkothanath)\
**Post date:** [September 12, 2022, 12:03pm UTC](https://discuss.elastic.co/t/check-if-index-value-is-substring-of-input-string/314191/1 "2022-09-12T12:03:42Z")

</div>

I have an index with field and value like(ES\_VAL: AMERICAN EXPRESS),  
I want to check if the entire ES\_VAL is substring of an input string(eg: CANADA AMERICAN EXPRESS).  
this is reverse of normal substring operation as we have to check if value in index is substring of input string.

should I use contains on doc[ES\_VAL] against input string for this? or is there any solution exists.

thanks for the help!

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [September 12, 2022, 1:15pm UTC](https://discuss.elastic.co/t/check-if-index-value-is-substring-of-input-string/314191/2 "2022-09-12T13:15:24Z")

</div>

Hi @rahulkothanath .

Should respect terms order? Look [Match Phrase Query.](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html)

---

<div class="post-metadata">

**Author:** ![rahulkothanath](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahulkothanath/32/99122_2.png) [@rahulkothanath](https://discuss.elastic.co/u/rahulkothanath)\
**Post date:** [September 12, 2022, 1:24pm UTC](https://discuss.elastic.co/t/check-if-index-value-is-substring-of-input-string/314191/3 "2022-09-12T13:24:27Z")

</div>

order matters.  
we are looking for reverse of match Phrase Query. want to check value in index is substring of query string but Match Phrase Query checks query string is substring of index value.  
eg: Elasticsearch contains field ES\_VAL with value AMERICAN EXPRESS and query string parameter is CANADA AMERICAL EXPRESS.

---

<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:** [October 10, 2022, 1:25pm UTC](https://discuss.elastic.co/t/check-if-index-value-is-substring-of-input-string/314191/4 "2022-10-10T13:25:19Z")

</div>

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