# Stopwords are not working in custom tokenizer

**URL:** <https://discuss.elastic.co/t/stopwords-are-not-working-in-custom-tokenizer/269033>\
**Category:** Elasticsearch\
**Created:** [April 1, 2021, 1:23pm UTC](https://discuss.elastic.co/t/stopwords-are-not-working-in-custom-tokenizer/269033 "2021-04-01T13:23:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tusharl](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@tusharl](https://discuss.elastic.co/u/tusharl)\
**Post date:** [April 1, 2021, 1:23pm UTC](https://discuss.elastic.co/t/stopwords-are-not-working-in-custom-tokenizer/269033/1 "2021-04-01T13:23:22Z")

</div>

Consider below example

```auto
    GET _analyze
    {
      "tokenizer": {
        "pattern" : ",",
        "type" : "pattern"
      },
      "filter": [
        { "type": "edge_ngram",
          "min_gram": 2,
          "max_gram": 10
        },
        {
          "type" : "stop",
          "stopwords" : ["ab"]
        }
      ],
      "text": "ab bcd,cde"
    }

```

If I am using above configuration then I should expect following tokens:  
["bc", "bcd", "cd", "cde"]

but I am getting below list of tokens:  
["ab", "ab b", "ab bc", "ab bcd", "cd", "cde"]

What is wrong with configuration of edge\_ngram?  
How do I achieve first sets of token in case of edge\_ngram and custom tokenizer?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 1, 2021, 2:13pm UTC](https://discuss.elastic.co/t/stopwords-are-not-working-in-custom-tokenizer/269033/2 "2021-04-01T14:13:39Z")

</div>

Your tokenizer splits based on `,` only, giving the tokens `ab bcd` and `cde`. This is then broken down into edge ngrams, which gives the result you see. To get the results you want you probably need to use a different tokenizer.

---

<div class="post-metadata">

**Author:** ![tusharl](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@tusharl](https://discuss.elastic.co/u/tusharl)\
**Post date:** [April 1, 2021, 2:23pm UTC](https://discuss.elastic.co/t/stopwords-are-not-working-in-custom-tokenizer/269033/3 "2021-04-01T14:23:47Z")

</div>

Yes. You are right. I will get two tokens `ab bcd` and `cde` but at same time I have another stopword filter which should remove `ab` from `ab bcd` and then create more tokens as per nedge\_gram. If I use standard token analyzer instead of pattern tokenizer then things are working perfectly fine(meaning it is removing stopword) but again standard tokenizer is not desired.

---

<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:** [April 29, 2021, 2:24pm UTC](https://discuss.elastic.co/t/stopwords-are-not-working-in-custom-tokenizer/269033/4 "2021-04-29T14:24:19Z")

</div>

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