standard-tokenizer.asciidoc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. [[analysis-standard-tokenizer]]
  2. === Standard Tokenizer
  3. The `standard` tokenizer provides grammar based tokenization (based on the
  4. Unicode Text Segmentation algorithm, as specified in
  5. http://unicode.org/reports/tr29/[Unicode Standard Annex #29]) and works well
  6. for most languages.
  7. [float]
  8. === Example output
  9. [source,js]
  10. ---------------------------
  11. POST _analyze
  12. {
  13. "tokenizer": "standard",
  14. "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
  15. }
  16. ---------------------------
  17. // CONSOLE
  18. /////////////////////
  19. [source,js]
  20. ----------------------------
  21. {
  22. "tokens": [
  23. {
  24. "token": "The",
  25. "start_offset": 0,
  26. "end_offset": 3,
  27. "type": "<ALPHANUM>",
  28. "position": 0
  29. },
  30. {
  31. "token": "2",
  32. "start_offset": 4,
  33. "end_offset": 5,
  34. "type": "<NUM>",
  35. "position": 1
  36. },
  37. {
  38. "token": "QUICK",
  39. "start_offset": 6,
  40. "end_offset": 11,
  41. "type": "<ALPHANUM>",
  42. "position": 2
  43. },
  44. {
  45. "token": "Brown",
  46. "start_offset": 12,
  47. "end_offset": 17,
  48. "type": "<ALPHANUM>",
  49. "position": 3
  50. },
  51. {
  52. "token": "Foxes",
  53. "start_offset": 18,
  54. "end_offset": 23,
  55. "type": "<ALPHANUM>",
  56. "position": 4
  57. },
  58. {
  59. "token": "jumped",
  60. "start_offset": 24,
  61. "end_offset": 30,
  62. "type": "<ALPHANUM>",
  63. "position": 5
  64. },
  65. {
  66. "token": "over",
  67. "start_offset": 31,
  68. "end_offset": 35,
  69. "type": "<ALPHANUM>",
  70. "position": 6
  71. },
  72. {
  73. "token": "the",
  74. "start_offset": 36,
  75. "end_offset": 39,
  76. "type": "<ALPHANUM>",
  77. "position": 7
  78. },
  79. {
  80. "token": "lazy",
  81. "start_offset": 40,
  82. "end_offset": 44,
  83. "type": "<ALPHANUM>",
  84. "position": 8
  85. },
  86. {
  87. "token": "dog's",
  88. "start_offset": 45,
  89. "end_offset": 50,
  90. "type": "<ALPHANUM>",
  91. "position": 9
  92. },
  93. {
  94. "token": "bone",
  95. "start_offset": 51,
  96. "end_offset": 55,
  97. "type": "<ALPHANUM>",
  98. "position": 10
  99. }
  100. ]
  101. }
  102. ----------------------------
  103. // TESTRESPONSE
  104. /////////////////////
  105. The above sentence would produce the following terms:
  106. [source,text]
  107. ---------------------------
  108. [ The, 2, QUICK, Brown, Foxes, jumped, over, the, lazy, dog's, bone ]
  109. ---------------------------
  110. [float]
  111. === Configuration
  112. The `standard` tokenizer accepts the following parameters:
  113. [horizontal]
  114. `max_token_length`::
  115. The maximum token length. If a token is seen that exceeds this length then
  116. it is split at `max_token_length` intervals. Defaults to `255`.
  117. [float]
  118. === Example configuration
  119. In this example, we configure the `standard` tokenizer to have a
  120. `max_token_length` of 5 (for demonstration purposes):
  121. [source,js]
  122. ----------------------------
  123. PUT my_index
  124. {
  125. "settings": {
  126. "analysis": {
  127. "analyzer": {
  128. "my_analyzer": {
  129. "tokenizer": "my_tokenizer"
  130. }
  131. },
  132. "tokenizer": {
  133. "my_tokenizer": {
  134. "type": "standard",
  135. "max_token_length": 5
  136. }
  137. }
  138. }
  139. }
  140. }
  141. GET _cluster/health?wait_for_status=yellow
  142. POST my_index/_analyze
  143. {
  144. "analyzer": "my_analyzer",
  145. "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
  146. }
  147. ----------------------------
  148. // CONSOLE
  149. /////////////////////
  150. [source,js]
  151. ----------------------------
  152. {
  153. "tokens": [
  154. {
  155. "token": "The",
  156. "start_offset": 0,
  157. "end_offset": 3,
  158. "type": "<ALPHANUM>",
  159. "position": 0
  160. },
  161. {
  162. "token": "2",
  163. "start_offset": 4,
  164. "end_offset": 5,
  165. "type": "<NUM>",
  166. "position": 1
  167. },
  168. {
  169. "token": "QUICK",
  170. "start_offset": 6,
  171. "end_offset": 11,
  172. "type": "<ALPHANUM>",
  173. "position": 2
  174. },
  175. {
  176. "token": "Brown",
  177. "start_offset": 12,
  178. "end_offset": 17,
  179. "type": "<ALPHANUM>",
  180. "position": 3
  181. },
  182. {
  183. "token": "Foxes",
  184. "start_offset": 18,
  185. "end_offset": 23,
  186. "type": "<ALPHANUM>",
  187. "position": 4
  188. },
  189. {
  190. "token": "jumpe",
  191. "start_offset": 24,
  192. "end_offset": 29,
  193. "type": "<ALPHANUM>",
  194. "position": 5
  195. },
  196. {
  197. "token": "d",
  198. "start_offset": 29,
  199. "end_offset": 30,
  200. "type": "<ALPHANUM>",
  201. "position": 6
  202. },
  203. {
  204. "token": "over",
  205. "start_offset": 31,
  206. "end_offset": 35,
  207. "type": "<ALPHANUM>",
  208. "position": 7
  209. },
  210. {
  211. "token": "the",
  212. "start_offset": 36,
  213. "end_offset": 39,
  214. "type": "<ALPHANUM>",
  215. "position": 8
  216. },
  217. {
  218. "token": "lazy",
  219. "start_offset": 40,
  220. "end_offset": 44,
  221. "type": "<ALPHANUM>",
  222. "position": 9
  223. },
  224. {
  225. "token": "dog's",
  226. "start_offset": 45,
  227. "end_offset": 50,
  228. "type": "<ALPHANUM>",
  229. "position": 10
  230. },
  231. {
  232. "token": "bone",
  233. "start_offset": 51,
  234. "end_offset": 55,
  235. "type": "<ALPHANUM>",
  236. "position": 11
  237. }
  238. ]
  239. }
  240. ----------------------------
  241. // TESTRESPONSE
  242. /////////////////////
  243. The above example produces the following terms:
  244. [source,text]
  245. ---------------------------
  246. [ The, 2, QUICK, Brown, Foxes, jumpe, d, over, the, lazy, dog's, bone ]
  247. ---------------------------