whitespace-analyzer.asciidoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. [[analysis-whitespace-analyzer]]
  2. === Whitespace Analyzer
  3. The `whitespace` analyzer breaks text into terms whenever it encounters a
  4. whitespace character.
  5. [float]
  6. === Example output
  7. [source,js]
  8. ---------------------------
  9. POST _analyze
  10. {
  11. "analyzer": "whitespace",
  12. "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
  13. }
  14. ---------------------------
  15. // CONSOLE
  16. /////////////////////
  17. [source,console-result]
  18. ----------------------------
  19. {
  20. "tokens": [
  21. {
  22. "token": "The",
  23. "start_offset": 0,
  24. "end_offset": 3,
  25. "type": "word",
  26. "position": 0
  27. },
  28. {
  29. "token": "2",
  30. "start_offset": 4,
  31. "end_offset": 5,
  32. "type": "word",
  33. "position": 1
  34. },
  35. {
  36. "token": "QUICK",
  37. "start_offset": 6,
  38. "end_offset": 11,
  39. "type": "word",
  40. "position": 2
  41. },
  42. {
  43. "token": "Brown-Foxes",
  44. "start_offset": 12,
  45. "end_offset": 23,
  46. "type": "word",
  47. "position": 3
  48. },
  49. {
  50. "token": "jumped",
  51. "start_offset": 24,
  52. "end_offset": 30,
  53. "type": "word",
  54. "position": 4
  55. },
  56. {
  57. "token": "over",
  58. "start_offset": 31,
  59. "end_offset": 35,
  60. "type": "word",
  61. "position": 5
  62. },
  63. {
  64. "token": "the",
  65. "start_offset": 36,
  66. "end_offset": 39,
  67. "type": "word",
  68. "position": 6
  69. },
  70. {
  71. "token": "lazy",
  72. "start_offset": 40,
  73. "end_offset": 44,
  74. "type": "word",
  75. "position": 7
  76. },
  77. {
  78. "token": "dog's",
  79. "start_offset": 45,
  80. "end_offset": 50,
  81. "type": "word",
  82. "position": 8
  83. },
  84. {
  85. "token": "bone.",
  86. "start_offset": 51,
  87. "end_offset": 56,
  88. "type": "word",
  89. "position": 9
  90. }
  91. ]
  92. }
  93. ----------------------------
  94. /////////////////////
  95. The above sentence would produce the following terms:
  96. [source,text]
  97. ---------------------------
  98. [ The, 2, QUICK, Brown-Foxes, jumped, over, the, lazy, dog's, bone. ]
  99. ---------------------------
  100. [float]
  101. === Configuration
  102. The `whitespace` analyzer is not configurable.
  103. [float]
  104. === Definition
  105. It consists of:
  106. Tokenizer::
  107. * <<analysis-whitespace-tokenizer,Whitespace Tokenizer>>
  108. If you need to customize the `whitespace` analyzer then you need to
  109. recreate it as a `custom` analyzer and modify it, usually by adding
  110. token filters. This would recreate the built-in `whitespace` analyzer
  111. and you can use it as a starting point for further customization:
  112. [source,js]
  113. ----------------------------------------------------
  114. PUT /whitespace_example
  115. {
  116. "settings": {
  117. "analysis": {
  118. "analyzer": {
  119. "rebuilt_whitespace": {
  120. "tokenizer": "whitespace",
  121. "filter": [ <1>
  122. ]
  123. }
  124. }
  125. }
  126. }
  127. }
  128. ----------------------------------------------------
  129. // CONSOLE
  130. // TEST[s/\n$/\nstartyaml\n - compare_analyzers: {index: whitespace_example, first: whitespace, second: rebuilt_whitespace}\nendyaml\n/]
  131. <1> You'd add any token filters here.