# Query dsl, must and must\_not

**URL:** <https://discuss.elastic.co/t/query-dsl-must-and-must-not/238542>\
**Category:** Elasticsearch\
**Created:** [June 24, 2020, 5:47pm UTC](https://discuss.elastic.co/t/query-dsl-must-and-must-not/238542 "2020-06-24T17:47:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [June 24, 2020, 5:47pm UTC](https://discuss.elastic.co/t/query-dsl-must-and-must-not/238542/1 "2020-06-24T17:47:40Z")

</div>

I have a  
version: v100.01  
version: v100.01.xyz

how do I only match v100.01 either using regexp or wildcard

following both query gives me both result

```
{
    "query": {
        "regexp": { "version": "v<0-9><0-9><0-9>.<0-9><0-9>" }
    }
}

{
  "query": { 
    "wildcard": { "version": "v???.??" }
    }
}
```

---

<div class="post-metadata">

**Author:** ![Vinayak\_Sapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinayak_sapre/32/45939_2.png) [@Vinayak\_Sapre](https://discuss.elastic.co/u/Vinayak_Sapre)\
**Post date:** [June 25, 2020, 6:22am UTC](https://discuss.elastic.co/t/query-dsl-must-and-must-not/238542/2 "2020-06-25T06:22:43Z")

</div>

Sachin,  
What is the type of the version field? text or keyword? Both queries should work if type is keyword.

If type is text the regex pattern you are using will be applied to each token.

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [June 25, 2020, 2:41pm UTC](https://discuss.elastic.co/t/query-dsl-must-and-must-not/238542/3 "2020-06-25T14:41:31Z")

</div>

that is it. I was not using keyword.  
I have this working like this now.

```
{
  "query": {
    "bool": {
      "must_not": [
        {
          "wildcard": { "version.keyword": "v???.??.???" }
        }
      ],
      "must": [
        {
          "regexp": { "version.keyword": "v<0-9><0-9><0-9>.<0-9><0-9>" }
        }
      ]
    }
  }
}
```

---

<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 23, 2020, 2:41pm UTC](https://discuss.elastic.co/t/query-dsl-must-and-must-not/238542/4 "2020-07-23T14:41:39Z")

</div>

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