Multiplexer token filter

The multiplexer token filter allows you to create multiple versions of the same token by applying different filters. This is useful when you want to analyze the same token in multiple ways. For example, you may want to analyze a token using different stemming, synonyms, or n-gram filters and use all of the generated tokens together. This token filter works by duplicating the token stream and applying different filters to each copy.

The multiplexer token filter removes duplicate tokens from the token stream.

The multiplexer token filter does not support multiword synonym or synonym_graph token filters or shingle token filters because they need to analyze not only the current token but also upcoming tokens in order to determine how to transform the input correctly.

Parameters

The multiplexer token filter can be configured with the following parameters.

ParameterRequired/OptionalData typeDescription
filtersOptionalList of stringsA comma-separated list of token filters to apply to each copy of the token stream. Default is an empty list.
preserve_originalOptionalBooleanWhether to keep the original token as one of the outputs. Default is true.

Example

The following example request creates a new index named multiplexer_index and configures an analyzer with a multiplexer filter:

  1. PUT /multiplexer_index
  2. {
  3. "settings": {
  4. "analysis": {
  5. "filter": {
  6. "english_stemmer": {
  7. "type": "stemmer",
  8. "name": "english"
  9. },
  10. "synonym_filter": {
  11. "type": "synonym",
  12. "synonyms": [
  13. "quick,fast"
  14. ]
  15. },
  16. "multiplexer_filter": {
  17. "type": "multiplexer",
  18. "filters": ["english_stemmer", "synonym_filter"],
  19. "preserve_original": true
  20. }
  21. },
  22. "analyzer": {
  23. "multiplexer_analyzer": {
  24. "type": "custom",
  25. "tokenizer": "standard",
  26. "filter": [
  27. "multiplexer_filter"
  28. ]
  29. }
  30. }
  31. }
  32. }
  33. }

copy

Generated tokens

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

  1. POST /multiplexer_index/_analyze
  2. {
  3. "analyzer": "multiplexer_analyzer",
  4. "text": "The slow turtle hides from the quick dog"
  5. }

copy

The response contains the generated tokens:

  1. {
  2. "tokens": [
  3. {
  4. "token": "The",
  5. "start_offset": 0,
  6. "end_offset": 3,
  7. "type": "<ALPHANUM>",
  8. "position": 0
  9. },
  10. {
  11. "token": "slow",
  12. "start_offset": 4,
  13. "end_offset": 8,
  14. "type": "<ALPHANUM>",
  15. "position": 1
  16. },
  17. {
  18. "token": "turtle",
  19. "start_offset": 9,
  20. "end_offset": 15,
  21. "type": "<ALPHANUM>",
  22. "position": 2
  23. },
  24. {
  25. "token": "turtl",
  26. "start_offset": 9,
  27. "end_offset": 15,
  28. "type": "<ALPHANUM>",
  29. "position": 2
  30. },
  31. {
  32. "token": "hides",
  33. "start_offset": 16,
  34. "end_offset": 21,
  35. "type": "<ALPHANUM>",
  36. "position": 3
  37. },
  38. {
  39. "token": "hide",
  40. "start_offset": 16,
  41. "end_offset": 21,
  42. "type": "<ALPHANUM>",
  43. "position": 3
  44. },
  45. {
  46. "token": "from",
  47. "start_offset": 22,
  48. "end_offset": 26,
  49. "type": "<ALPHANUM>",
  50. "position": 4
  51. },
  52. {
  53. "token": "the",
  54. "start_offset": 27,
  55. "end_offset": 30,
  56. "type": "<ALPHANUM>",
  57. "position": 5
  58. },
  59. {
  60. "token": "quick",
  61. "start_offset": 31,
  62. "end_offset": 36,
  63. "type": "<ALPHANUM>",
  64. "position": 6
  65. },
  66. {
  67. "token": "fast",
  68. "start_offset": 31,
  69. "end_offset": 36,
  70. "type": "SYNONYM",
  71. "position": 6
  72. },
  73. {
  74. "token": "dog",
  75. "start_offset": 37,
  76. "end_offset": 40,
  77. "type": "<ALPHANUM>",
  78. "position": 7
  79. }
  80. ]
  81. }