# Using a must\_not filter on 'drone' returns a document containing 'drone'

**URL:** <https://discuss.elastic.co/t/using-a-must-not-filter-on-drone-returns-a-document-containing-drone/315150>\
**Category:** Elasticsearch\
**Created:** [September 26, 2022, 9:06am UTC](https://discuss.elastic.co/t/using-a-must-not-filter-on-drone-returns-a-document-containing-drone/315150 "2022-09-26T09:06:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cracanut](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cracanut/32/107727_2.png) [@cracanut](https://discuss.elastic.co/u/cracanut)\
**Post date:** [September 26, 2022, 9:06am UTC](https://discuss.elastic.co/t/using-a-must-not-filter-on-drone-returns-a-document-containing-drone/315150/1 "2022-09-26T09:06:40Z")

</div>

Using a must\_not filter on 'drone' returns a document containing 'drone':

Cluster analyzer settings:

```auto
"analysis": {
      "filter": {
        "english_stemmer": {
          "type": "stemmer",
          "language": "english"
        },
        "english_possessive_stemmer": {
          "type": "stemmer",
          "language": "possessive_english"
        }
      },
      "analyzer": {
        "eng_stemmer": {
          "tokenizer": "whitespace",
          "char_filter": ["html_strip", "custom_char_filter_start_of_word", "custom_char_filter_end_of_word"],
          "filter": [
            "english_possessive_stemmer",
            "lowercase",
            "english_stemmer"
          ]
        }
      },
      "char_filter": {
        "custom_char_filter_end_of_word": {
          "type": "pattern_replace",
          "pattern": "[\\W]+(\\s|$)",
          "replacement": " "
        },
        "custom_char_filter_start_of_word": {
          "type": "pattern_replace",
          "pattern": "(\\s|^)[\\W]+",
          "replacement": " "
        }
      }
  }

```

When using this query:

```auto
{
  "query": {
    "bool":{
      "must_not": [
        {
          "match": {
            "title": "drone"
          }
        }
      ],
      "must": [
        {
          "match": {
            "title": "wing"
          }
        }
      ]
    }
  }
}

```

I get a document with the following title in my results:

```auto
"title": "Hydrodynamic or streamlined profile for forming e.g. drone`s wing, has core comprising active section deformed under effect of variation of temperature of active layer inducing amplitude and direction deformation in zones of envelope",

```

I tried the /\_analyze for both the search term and the title and both are stemmed to 'drone', yet the document is not filtered out of the result.

Am I missing something or is this a bug?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 26, 2022, 10:11am UTC](https://discuss.elastic.co/t/using-a-must-not-filter-on-drone-returns-a-document-containing-drone/315150/2 "2022-09-26T10:11:29Z")

</div>

What is the mapping for the field `title`?

Is "drone`s" really analyzed as `drone`? Could you share the output of:

```auto
GET /INDEX/_analyze
{
  "field" : "title",
  "text" : Hydrodynamic or streamlined profile for forming e.g. drone`s wing, has core comprising active section deformed under effect of variation of temperature of active layer inducing amplitude and direction deformation in zones of envelope"
}

```

---

<div class="post-metadata">

**Author:** ![cracanut](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cracanut/32/107727_2.png) [@cracanut](https://discuss.elastic.co/u/cracanut)\
**Post date:** [September 26, 2022, 10:23am UTC](https://discuss.elastic.co/t/using-a-must-not-filter-on-drone-returns-a-document-containing-drone/315150/3 "2022-09-26T10:23:57Z")

</div>

Thank you for the reply.

The title field uses the 'eng\_stemmer' analyzer.

I just redid the \_analyze and found the issue (I must have overlooked it earlier):

> drone's

is reduced to

> drone'

(notice the single quote not being removed).

I expected the 'english\_stemmer' or 'english\_possessive\_stemmer' to remove the quote as well as this is a regular occurence in the English language?

Edit: perhaps it's because it doesn't appear to be a standard single quote?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 26, 2022, 10:39am UTC](https://discuss.elastic.co/t/using-a-must-not-filter-on-drone-returns-a-document-containing-drone/315150/4 "2022-09-26T10:39:33Z")

</div>

So that's the reason when searching for `drone` it can not match with "drone'"...

Instead of using a `whitespace` tokenizer, I'd use the `standard` one. Could you check that?

---

<div class="post-metadata">

**Author:** ![cracanut](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cracanut/32/107727_2.png) [@cracanut](https://discuss.elastic.co/u/cracanut)\
**Post date:** [September 26, 2022, 10:59am UTC](https://discuss.elastic.co/t/using-a-must-not-filter-on-drone-returns-a-document-containing-drone/315150/5 "2022-09-26T10:59:17Z")

</div>

We can't use the standard tokenizer. We need to do a search on e.g. match "C/C" but the standard tokenizer removes the forward slash resulting in documents with "c c" in the result.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 26, 2022, 11:53am UTC](https://discuss.elastic.co/t/using-a-must-not-filter-on-drone-returns-a-document-containing-drone/315150/6 "2022-09-26T11:53:15Z")

</div>

I checked the documentation and the `standard` tokenizer won't work I think anyway.

May be look at

> **[Character group tokenizer | Elasticsearch Guide \[8.4\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-chargroup-tokenizer.html)**

---

<div class="post-metadata">

**Author:** ![cracanut](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cracanut/32/107727_2.png) [@cracanut](https://discuss.elastic.co/u/cracanut)\
**Post date:** [September 26, 2022, 3:03pm UTC](https://discuss.elastic.co/t/using-a-must-not-filter-on-drone-returns-a-document-containing-drone/315150/7 "2022-09-26T15:03:26Z")

</div>

Looks like replacing every

> `

with a standard single quote (using a mapping char filter) seems to be working. "drone`s" is now correctly stemmed to "drone".

---

<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 24, 2022, 3:04pm UTC](https://discuss.elastic.co/t/using-a-must-not-filter-on-drone-returns-a-document-containing-drone/315150/8 "2022-10-24T15:04:12Z")

</div>

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