standard-tokenizer.asciidoc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. POST my_index/_analyze
  142. {
  143. "analyzer": "my_analyzer",
  144. "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
  145. }
  146. ----------------------------
  147. // CONSOLE
  148. /////////////////////
  149. [source,js]
  150. ----------------------------
  151. {
  152. "tokens": [
  153. {
  154. "token": "The",
  155. "start_offset": 0,
  156. "end_offset": 3,
  157. "type": "<ALPHANUM>",
  158. "position": 0
  159. },
  160. {
  161. "token": "2",
  162. "start_offset": 4,
  163. "end_offset": 5,
  164. "type": "<NUM>",
  165. "position": 1
  166. },
  167. {
  168. "token": "QUICK",
  169. "start_offset": 6,
  170. "end_offset": 11,
  171. "type": "<ALPHANUM>",
  172. "position": 2
  173. },
  174. {
  175. "token": "Brown",
  176. "start_offset": 12,
  177. "end_offset": 17,
  178. "type": "<ALPHANUM>",
  179. "position": 3
  180. },
  181. {
  182. "token": "Foxes",
  183. "start_offset": 18,
  184. "end_offset": 23,
  185. "type": "<ALPHANUM>",
  186. "position": 4
  187. },
  188. {
  189. "token": "jumpe",
  190. "start_offset": 24,
  191. "end_offset": 29,
  192. "type": "<ALPHANUM>",
  193. "position": 5
  194. },
  195. {
  196. "token": "d",
  197. "start_offset": 29,
  198. "end_offset": 30,
  199. "type": "<ALPHANUM>",
  200. "position": 6
  201. },
  202. {
  203. "token": "over",
  204. "start_offset": 31,
  205. "end_offset": 35,
  206. "type": "<ALPHANUM>",
  207. "position": 7
  208. },
  209. {
  210. "token": "the",
  211. "start_offset": 36,
  212. "end_offset": 39,
  213. "type": "<ALPHANUM>",
  214. "position": 8
  215. },
  216. {
  217. "token": "lazy",
  218. "start_offset": 40,
  219. "end_offset": 44,
  220. "type": "<ALPHANUM>",
  221. "position": 9
  222. },
  223. {
  224. "token": "dog's",
  225. "start_offset": 45,
  226. "end_offset": 50,
  227. "type": "<ALPHANUM>",
  228. "position": 10
  229. },
  230. {
  231. "token": "bone",
  232. "start_offset": 51,
  233. "end_offset": 55,
  234. "type": "<ALPHANUM>",
  235. "position": 11
  236. }
  237. ]
  238. }
  239. ----------------------------
  240. // TESTRESPONSE
  241. /////////////////////
  242. The above example produces the following terms:
  243. [source,text]
  244. ---------------------------
  245. [ The, 2, QUICK, Brown, Foxes, jumpe, d, over, the, lazy, dog's, bone ]
  246. ---------------------------