whitespace-analyzer.asciidoc 2.9 KB

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