# Illegal\_argument\_exception while creating new index

**URL:** <https://discuss.elastic.co/t/illegal-argument-exception-while-creating-new-index/219074>\
**Category:** Elasticsearch\
**Created:** [February 12, 2020, 7:40pm UTC](https://discuss.elastic.co/t/illegal-argument-exception-while-creating-new-index/219074 "2020-02-12T19:40:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JustSomeoneOnline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justsomeoneonline/32/62574_2.png) [@JustSomeoneOnline](https://discuss.elastic.co/u/JustSomeoneOnline)\
**Post date:** [February 12, 2020, 7:40pm UTC](https://discuss.elastic.co/t/illegal-argument-exception-while-creating-new-index/219074/1 "2020-02-12T19:40:03Z")

</div>

Hi. I'm running into issues when trying to create a new index in ElasticSearch 7.5

The error message is:

`The difference between max_gram and min_gram in NGram Tokenizer must be less than or equal to: [1] but was [18]. This limit can be set by changing the [index.max_ngram_diff] index level setting.`

I'm learning about custom analyzers so it could be something I'm unknowingly doing wrong. I've read about this issue on two other topics [here](https://discuss.elastic.co/t/how-large-can-we-increment-index-max-ngram-diff/187303) and [here](https://discuss.elastic.co/t/error-trying-to-update-index-setting-max-ngram-diff/206492) If it's as simple as changing index.max\_ngram\_diff that's fine. The linked questions above point to an issue where that didn't seem to work as the user expected.

I'm most curious about where to get more info & learn rather than a spoon-fed answer. Can anyone point me in the right direction?

Here is the analysis section of my PUT request.

```
  "analysis": {
            "analyzer": {
                "case_insensitive_sort": {
                    "filter": [
                        "lowercase"
                    ],
                    "tokenizer": "keyword"
                },
                "email": {
                    "filter": [
                        "email",
                        "lowercase",
                        "unique"
                    ],
                    "tokenizer": "uax_url_email"
                },
                "ngram_filter_analyzer": {
                    "type": "custom",
                    "filter": [
                        "lowercase",
                        "ngram_filter"
                    ],
                    "tokenizer": "standard"
                }
            },
            "filter": {
                "email": {
                    "preserve_original": "1",
                    "type": "pattern_capture",
                    "patterns": [
                        "([^@]+)",
                        "(\\p{L}+)",
                        "(\\d+)",
                        "@(.+)",
                        "([^-@]+)"
                    ]
                },
                "ngram_filter": {
                    "min_gram": "2",
                    "type": "nGram",
                    "max_gram": "20"
                }
            }
        }
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 13, 2020, 9:54am UTC](https://discuss.elastic.co/t/illegal-argument-exception-while-creating-new-index/219074/2 "2020-02-13T09:54:41Z")

</div>

The error message states that the difference between `min_gram` and `max_gram` is 18, which is `20-2`, which in turn are your current settings.

There is also a mention of a setting how you can change that behaviour, but that should be explicitely set, as this means you will index a lot of terms and you know what you do, see [https://www.elastic.co/guide/en/elasticsearch/reference/7.5/index-modules.html#index-max-ngram-diff](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/index-modules.html#index-max-ngram-diff)

---

<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:** [March 12, 2020, 9:54am UTC](https://discuss.elastic.co/t/illegal-argument-exception-while-creating-new-index/219074/3 "2020-03-12T09:54:46Z")

</div>

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