# Using must\_not and wildcard to search

**URL:** <https://discuss.elastic.co/t/using-must-not-and-wildcard-to-search/134590>\
**Category:** Elasticsearch\
**Created:** [June 5, 2018, 10:37am UTC](https://discuss.elastic.co/t/using-must-not-and-wildcard-to-search/134590 "2018-06-05T10:37:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sirbrian](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@sirbrian](https://discuss.elastic.co/u/sirbrian)\
**Post date:** [June 5, 2018, 10:37am UTC](https://discuss.elastic.co/t/using-must-not-and-wildcard-to-search/134590/1 "2018-06-05T10:37:30Z")

</div>

Hi,

I am new to Elasticsearch and Kibana. I am using the Kibana Dev Tools to search Elasticsearch. What I want to do is find all results that don't match a wildcard term. If I try this a search with

```
  "must_not": [
    {
    "match": {
      "message": "JOINNG"          
    }

```

it returns as expected - no results with message=JOINING

if I try with a wildcard however like so

```
  "must_not": [
    {
    "wildcard": {
      "message": "JOIN*"
    }

```

It returns messages with JOINING in. Can you use Wildcard with a must\_not statement?

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [June 5, 2018, 10:53am UTC](https://discuss.elastic.co/t/using-must-not-and-wildcard-to-search/134590/2 "2018-06-05T10:53:06Z")

</div>

What is the datatype of the message field?  
It must be _keyword_, as wildcard works only with **not analyzed** fields.

[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html)

---

<div class="post-metadata">

**Author:** ![sirbrian](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@sirbrian](https://discuss.elastic.co/u/sirbrian)\
**Post date:** [June 5, 2018, 11:34am UTC](https://discuss.elastic.co/t/using-must-not-and-wildcard-to-search/134590/3 "2018-06-05T11:34:13Z")

</div>

Its text. I did a GET \_mapping/field/message and it shows this. Doesn't not say whether its analysed or not. Is default analysed?

```
  "logstash-2018.05.31": {
    "mappings": {
      "fluentd": {
        "message": {
          "full_name": "message",
          "mapping": {
            "message": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            }
          }
        }
      }
    }
  },
```

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [June 5, 2018, 11:43am UTC](https://discuss.elastic.co/t/using-must-not-and-wildcard-to-search/134590/4 "2018-06-05T11:43:10Z")

</div>

Yes, that's the reason why it's not working,  
so in your query, you should use the "not analyzed" version of the message field, which is **message.keyword** , according to the mapping.

```
  "must_not": [
    {
    "wildcard": {
      "message.keyword": "JOIN*"
    }
```

---

<div class="post-metadata">

**Author:** ![sirbrian](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@sirbrian](https://discuss.elastic.co/u/sirbrian)\
**Post date:** [June 5, 2018, 11:56am UTC](https://discuss.elastic.co/t/using-must-not-and-wildcard-to-search/134590/5 "2018-06-05T11:56:07Z")

</div>

> [@klof](#):
>
> message.keyword

Thats it. Thanks very much klof

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [June 5, 2018, 2:48pm UTC](https://discuss.elastic.co/t/using-must-not-and-wildcard-to-search/134590/6 "2018-06-05T14:48:33Z")

</div>

@sirbrian you're welcome

---

<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 3, 2018, 2:48pm UTC](https://discuss.elastic.co/t/using-must-not-and-wildcard-to-search/134590/7 "2018-07-03T14:48:38Z")

</div>

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