# Issues creating custom\_analyzer

**URL:** <https://discuss.elastic.co/t/issues-creating-custom-analyzer/195325>\
**Category:** Elasticsearch\
**Created:** [August 15, 2019, 10:03am UTC](https://discuss.elastic.co/t/issues-creating-custom-analyzer/195325 "2019-08-15T10:03:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MinHan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/minhan/32/45055_2.png) [@MinHan](https://discuss.elastic.co/u/MinHan)\
**Post date:** [August 15, 2019, 10:03am UTC](https://discuss.elastic.co/t/issues-creating-custom-analyzer/195325/1 "2019-08-15T10:03:37Z")

</div>

I'm currently using python along with elasticsearch.  
My data only has 2 columns:

- "sms\_id"
- "msg\_txt"

I'm basically creating a custom n-gram analyzer and calling the ngram analyzer within my mapping for "msg\_txt" field only.

I'm not sure why I'm facing errors. Could someone help?  
Thank you!

Warmest Regards,  
Min Han

 ![03%20PM](https://us1.discourse-cdn.com/elastic/original/3X/0/9/09b548c34ca56449f991bd3fa66414d11d5d0725.png)

---

<div class="post-metadata">

**Author:** ![William\_Brafford](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/william_brafford/32/51559_2.png) [@William\_Brafford](https://discuss.elastic.co/u/William_Brafford)\
**Post date:** [August 15, 2019, 7:54pm UTC](https://discuss.elastic.co/t/issues-creating-custom-analyzer/195325/2 "2019-08-15T19:54:12Z")

</div>

Min Han,

It is hard for me to be sure from the screenshot, but it looks like you have defined the `tokenizer` in the `settings` block rather than the `analysis` block. That is, it looks like you have:

```auto
{
    "settings": {
        [...]
        "analysis": {
            "analyzer": {
                "my_ngram_analyzer": {
                    [...]
                }
            }
        },
        "tokenizer": {
            "ngram_tokenizer": {
                [...]
            },
        },
    },
    "mapping": {
        [...]
    }
}

```

...when you should have:

```auto
{
    "settings": {
        [...]
        "analysis": {
            "analyzer": {
                "my_ngram_analyzer": {
                    [...]
                }
            },
            "tokenizer": {
                "ngram_tokenizer": {
                    [...]
                },
            },
        }
    },
    "mapping": {
        [...]
    }
}

```

I hope this helps. One thing that might be useful to you on these forums is to paste code samples as text rather than as screenshots. It will make it easier for other community members to check on your code. Just make sure that you highlight your code and click the `</>` icon before you post, so that your code is well-formatted.

-William

---

<div class="post-metadata">

**Author:** ![MinHan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/minhan/32/45055_2.png) [@MinHan](https://discuss.elastic.co/u/MinHan)\
**Post date:** [August 16, 2019, 3:26am UTC](https://discuss.elastic.co/t/issues-creating-custom-analyzer/195325/3 "2019-08-16T03:26:01Z")

</div>

Thanks for taking the time to reply to me William!

I'm still receiving an error after making the amendments. By the way, I'm using python elasticsearch.

```
response = es.indices.create(
index='custom_analyzer',
body={
  "settings": {
    "number_of_shards": 5,
    "number_of_replicas": 0,   
    "analysis": {
      "analyzer": {
        "my_ngram_analyzer": {
            "filter": ["lowercase"],
            "tokenizer": "ngram_tokenizer"
        }
      },
        "tokenizer":{
            "ngram_tokenizer":{
                "type": "n_gram",
                "min_gram": 3,
                "max_gram": 3,
                "token_chars":[
                    "letter",
                    "digit"
                ]
            }
        }
  }
},
"mapping":{
    "properties":{
        "msg_txt":{
            "type": "text",
            "analyzer": "ngram_tokenizer"
        }
        
    }
}

```

}  
)

print(response)

 ![51%20AM](https://us1.discourse-cdn.com/elastic/original/3X/1/6/163fe5c94f023f9f912dbbf025ab9244abad9a47.png)

---

<div class="post-metadata">

**Author:** ![MinHan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/minhan/32/45055_2.png) [@MinHan](https://discuss.elastic.co/u/MinHan)\
**Post date:** [August 16, 2019, 7:41am UTC](https://discuss.elastic.co/t/issues-creating-custom-analyzer/195325/4 "2019-08-16T07:41:05Z")

</div>

Dear William,

Thanks for your help but I've resolved the error already. I should have a s in the "mapping", ngram and not n\_gram, and my analyzer should have been my\_ngram\_analyzer of course.

Once again thanks for your gracious help! (😄

---

<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:** [September 13, 2019, 7:53am UTC](https://discuss.elastic.co/t/issues-creating-custom-analyzer/195325/5 "2019-09-13T07:53:35Z")

</div>

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