1. Docs

N-gram token filter

Changes token text to an ngram. For example, you can use the n-gram token filter to change fox to [ f, fo, o, ox, x ].

Add to an analyzer

ngram can be added to any analyzer as a filter.

JSON
"analyzer": { "substring": { "type": "custom", "tokenizer": "standard", "filter": ["ngram"] } }

Configurable parameters

  • min_gram (Optional, integer) Minimum length of characters in a gram. Defaults to 1.
  • max_gram (Optional, integer) Maximum length of characters in a gram. Defaults to 2.
  • preserve_original (Optional, Boolean) Emits original token when set to true. Defaults to false.

For example a 1 to 3 character edge-ngram could be configured and used like this:

JSON
"settings": { "analysis": { "analyzer": { "custom_analyzer": { "type": "custom", "filter": ["1_3_ngrams"] } }, "filter": { "1_3_ngrams": { "type": "ngram", "min_gram": 1, "max_gram": 3 } } } }

Was this page helpful?