Search code examples
elasticsearchelasticsearch-5

How to adjust max_gram for text field in elastic search?


The issue is, I have an email field in elastic search documents with max_gram = 20, So if I have email_address with characters more than max_gram, it will be not found with the search query, I know I can add .sort on the field to search with the whole text but if I entered email with more than max_gram and not the whole email it will never found. So what can I do?


Solution

  • First thing, you shouldn't create the gram on mail-id and elasticsearch already provides a UAX_URL email tokenizer to properly tokenizer the mail-id.

    Still if you don't want to change it to above recommended way, then you should change the index.max_gram_diff setting and increase your max_gram value to higher number.

    Note, max_gram_diff is the difference between min gram and max gram.