Word delimiter graph token filter

The word_delimiter_graph token filter is used to split tokens at predefined characters and also offers optional token normalization based on customizable rules.

The word_delimiter_graph filter is used to remove punctuation from complex identifiers like part numbers or product IDs. In such cases, it is best used with the keyword tokenizer. For hyphenated words, use the synonym_graph token filter instead of the word_delimiter_graph filter because users frequently search for these terms both with and without hyphens.

By default, the filter applies the following rules.

DescriptionInputOutput
Treats non-alphanumeric characters as delimiters.ultra-fastultra, fast
Removes delimiters at the beginning or end of tokens.Z99++’Decoder’Z99, Decoder
Splits tokens when there is a transition between uppercase and lowercase letters.OpenSearchOpen, Search
Splits tokens when there is a transition between letters and numbers.T1000T, 1000
Removes the possessive (‘s) from the end of tokens.John’sJohn

It’s important not to use tokenizers that strip punctuation, like the standard tokenizer, with this filter. Doing so may prevent proper token splitting and interfere with options like catenate_all or preserve_original. We recommend using this filter with a keyword or whitespace tokenizer.

Parameters

You can configure the word_delimiter_graph token filter using the following parameters.

ParameterRequired/OptionalData typeDescription
adjust_offsetsOptionalBooleanDetermines whether the token offsets should be recalculated for split or concatenated tokens. When true, the filter adjusts the token offsets to accurately represent the token’s position within the token stream. This adjustment ensures that the token’s location in the text aligns with its modified form after processing, which is particularly useful for applications like highlighting or phrase queries. When false, the offsets remain unchanged, which may result in misalignment when the processed tokens are mapped back to their positions in the original text. If your analyzer uses filters like trim that change the token lengths without changing their offsets, we recommend setting this parameter to false. Default is true.
catenate_allOptionalBooleanProduces concatenated tokens from a sequence of alphanumeric parts. For example, “quick-fast-200” becomes [ quickfast200, quick, fast, 200 ]. Default is false.
catenate_numbersOptionalBooleanConcatenates numerical sequences. For example, “10-20-30” becomes [ 102030, 10, 20, 30 ]. Default is false.
catenate_wordsOptionalBooleanConcatenates alphabetic words. For example, “high-speed-level” becomes [ highspeedlevel, high, speed, level ]. Default is false.
generate_number_partsOptionalBooleanIf true, numeric tokens (tokens consisting of numbers only) are included in the output. Default is true.
generate_word_partsOptionalBooleanIf true, alphabetical tokens (tokens consisting of alphabetic characters only) are included in the output. Default is true.
ignore_keywordsOptionalBooleanWhether to process tokens marked as keywords. Default is false.
preserve_originalOptionalBooleanKeeps the original token (which may include non-alphanumeric delimiters) alongside the generated tokens in the output. For example, “auto-drive-300” becomes [ auto-drive-300, auto, drive, 300 ]. If true, the filter generates multi-position tokens not supported by indexing, so do not use this filter in an index analyzer or use the flatten_graph filter after this filter. Default is false.
protected_wordsOptionalArray of stringsSpecifies tokens that should not be split.
protected_words_pathOptionalStringSpecifies a path (absolute or relative to the config directory) to a file containing tokens that should not be separated by new lines.
split_on_case_changeOptionalBooleanSplits tokens where consecutive letters have different cases (one is lowercase and the other is uppercase). For example, “OpenSearch” becomes [ Open, Search ]. Default is true.
split_on_numericsOptionalBooleanSplits tokens where there are consecutive letters and numbers. For example “v8engine” will become [ v, 8, engine ]. Default is true.
stem_english_possessiveOptionalBooleanRemoves English possessive endings, such as ‘s. Default is true.
type_tableOptionalArray of stringsA custom map that specifies how to treat characters and whether to treat them as delimiters, which avoids unwanted splitting. For example, to treat a hyphen (-) as an alphanumeric character, specify [“- => ALPHA”] so that words are not split at hyphens. Valid types are:
- ALPHA: alphabetical
- ALPHANUM: alphanumeric
- DIGIT: numeric
- LOWER: lowercase alphabetical
- SUBWORD_DELIM: non-alphanumeric delimiter
- UPPER: uppercase alphabetical
type_table_pathOptionalStringSpecifies a path (absolute or relative to the config directory) to a file containing a custom character map. The map specifies how to treat characters and whether to treat them as delimiters, which avoids unwanted splitting. For valid types, see type_table.

Example

The following example request creates a new index named my-custom-index and configures an analyzer with a word_delimiter_graph filter:

  1. PUT /my-custom-index
  2. {
  3. "settings": {
  4. "analysis": {
  5. "analyzer": {
  6. "custom_analyzer": {
  7. "tokenizer": "keyword",
  8. "filter": [ "custom_word_delimiter_filter" ]
  9. }
  10. },
  11. "filter": {
  12. "custom_word_delimiter_filter": {
  13. "type": "word_delimiter_graph",
  14. "split_on_case_change": true,
  15. "split_on_numerics": true,
  16. "stem_english_possessive": true
  17. }
  18. }
  19. }
  20. }
  21. }

copy

Generated tokens

Use the following request to examine the tokens generated using the analyzer:

  1. GET /my-custom-index/_analyze
  2. {
  3. "analyzer": "custom_analyzer",
  4. "text": "FastCar's Model2023"
  5. }

copy

The response contains the generated tokens:

  1. {
  2. "tokens": [
  3. {
  4. "token": "Fast",
  5. "start_offset": 0,
  6. "end_offset": 4,
  7. "type": "word",
  8. "position": 0
  9. },
  10. {
  11. "token": "Car",
  12. "start_offset": 4,
  13. "end_offset": 7,
  14. "type": "word",
  15. "position": 1
  16. },
  17. {
  18. "token": "Model",
  19. "start_offset": 10,
  20. "end_offset": 15,
  21. "type": "word",
  22. "position": 2
  23. },
  24. {
  25. "token": "2023",
  26. "start_offset": 15,
  27. "end_offset": 19,
  28. "type": "word",
  29. "position": 3
  30. }
  31. ]
  32. }

Differences between the word_delimiter_graph and word_delimiter filters

Both the word_delimiter_graph and word_delimiter token filters generate tokens spanning multiple positions when any of the following parameters are set to true:

  • catenate_all
  • catenate_numbers
  • catenate_words
  • preserve_original

To illustrate the differences between these filters, consider the input text Pro-XT500.

word_delimiter_graph

The word_delimiter_graph filter assigns a positionLength attribute to multi-position tokens, indicating how many positions a token spans. This ensures that the filter always generates valid token graphs, making it suitable for use in advanced token graph scenarios. Although token graphs with multi-position tokens are not supported for indexing, they can still be useful in search scenarios. For example, queries like match_phrase can use these graphs to generate multiple subqueries from a single input string. For the example input text, the word_delimiter_graph filter generates the following tokens:

  • Pro (position 1)
  • XT500 (position 2)
  • ProXT500 (position 1, positionLength: 2)

The positionLength attribute the production of a valid graph to be used in advanced queries.

word_delimiter

In contrast, the word_delimiter filter does not assign a positionLength attribute to multi-position tokens, leading to invalid graphs when these tokens are present. For the example input text, the word_delimiter filter generates the following tokens:

  • Pro (position 1)
  • XT500 (position 2)
  • ProXT500 (position 1, no positionLength)

The lack of a positionLength attribute results in a token graph that is invalid for token streams containing multi-position tokens.