# Elastic Search Query to match Only if Specific value is present

**URL:** <https://discuss.elastic.co/t/elastic-search-query-to-match-only-if-specific-value-is-present/305796>\
**Category:** Elasticsearch\
**Created:** [May 27, 2022, 11:45am UTC](https://discuss.elastic.co/t/elastic-search-query-to-match-only-if-specific-value-is-present/305796 "2022-05-27T11:45:48Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [May 28, 2022, 11:30am UTC](https://discuss.elastic.co/t/elastic-search-query-to-match-only-if-specific-value-is-present/305796/3 "2022-05-28T11:30:41Z")

</div>

This is a related post.

> [@How to find docs that contain the exact specified terms](https://discuss.elastic.co/t/how-to-find-docs-that-contain-the-exact-specified-terms/295758/13):
>
> Hi @Cholley_Alexandre , I found another solution. If you don't mind duplication of 'A' or 'B', GET /test\_runtime/\_search { "query":{ "bool": { "filter": [{"term": {"my-field": "A"}}, {"term": {"my-field": "B"}}], "must\_not": [{ "regexp": { "my-field": "~(A|B)" } }] } } } will return what you want. If you want to distinguish duplication or order, you may need custom fingerprint strategy as…

---

_[View the full topic](https://discuss.elastic.co/t/elastic-search-query-to-match-only-if-specific-value-is-present/305796)._
