1
0

standard-tokenizer.asciidoc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. [[analysis-standard-tokenizer]]
  2. === Standard tokenizer
  3. ++++
  4. <titleabbrev>Standard</titleabbrev>
  5. ++++
  6. The `standard` tokenizer provides grammar based tokenization (based on the
  7. Unicode Text Segmentation algorithm, as specified in
  8. https://unicode.org/reports/tr29/[Unicode Standard Annex #29]) and works well
  9. for most languages.
  10. [discrete]
  11. === Example output
  12. [source,console]
  13. ---------------------------
  14. POST _analyze
  15. {
  16. "tokenizer": "standard",
  17. "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
  18. }
  19. ---------------------------
  20. /////////////////////
  21. [source,console-result]
  22. ----------------------------
  23. {
  24. "tokens": [
  25. {
  26. "token": "The",
  27. "start_offset": 0,
  28. "end_offset": 3,
  29. "type": "<ALPHANUM>",
  30. "position": 0
  31. },
  32. {
  33. "token": "2",
  34. "start_offset": 4,
  35. "end_offset": 5,
  36. "type": "<NUM>",
  37. "position": 1
  38. },
  39. {
  40. "token": "QUICK",
  41. "start_offset": 6,
  42. "end_offset": 11,
  43. "type": "<ALPHANUM>",
  44. "position": 2
  45. },
  46. {
  47. "token": "Brown",
  48. "start_offset": 12,
  49. "end_offset": 17,
  50. "type": "<ALPHANUM>",
  51. "position": 3
  52. },
  53. {
  54. "token": "Foxes",
  55. "start_offset": 18,
  56. "end_offset": 23,
  57. "type": "<ALPHANUM>",
  58. "position": 4
  59. },
  60. {
  61. "token": "jumped",
  62. "start_offset": 24,
  63. "end_offset": 30,
  64. "type": "<ALPHANUM>",
  65. "position": 5
  66. },
  67. {
  68. "token": "over",
  69. "start_offset": 31,
  70. "end_offset": 35,
  71. "type": "<ALPHANUM>",
  72. "position": 6
  73. },
  74. {
  75. "token": "the",
  76. "start_offset": 36,
  77. "end_offset": 39,
  78. "type": "<ALPHANUM>",
  79. "position": 7
  80. },
  81. {
  82. "token": "lazy",
  83. "start_offset": 40,
  84. "end_offset": 44,
  85. "type": "<ALPHANUM>",
  86. "position": 8
  87. },
  88. {
  89. "token": "dog's",
  90. "start_offset": 45,
  91. "end_offset": 50,
  92. "type": "<ALPHANUM>",
  93. "position": 9
  94. },
  95. {
  96. "token": "bone",
  97. "start_offset": 51,
  98. "end_offset": 55,
  99. "type": "<ALPHANUM>",
  100. "position": 10
  101. }
  102. ]
  103. }
  104. ----------------------------
  105. /////////////////////
  106. The above sentence would produce the following terms:
  107. [source,text]
  108. ---------------------------
  109. [ The, 2, QUICK, Brown, Foxes, jumped, over, the, lazy, dog's, bone ]
  110. ---------------------------
  111. [discrete]
  112. === Configuration
  113. The `standard` tokenizer accepts the following parameters:
  114. [horizontal]
  115. `max_token_length`::
  116. The maximum token length. If a token is seen that exceeds this length then
  117. it is split at `max_token_length` intervals. Defaults to `255`.
  118. [discrete]
  119. === Example configuration
  120. In this example, we configure the `standard` tokenizer to have a
  121. `max_token_length` of 5 (for demonstration purposes):
  122. [source,console]
  123. ----------------------------
  124. PUT my-index-000001
  125. {
  126. "settings": {
  127. "analysis": {
  128. "analyzer": {
  129. "my_analyzer": {
  130. "tokenizer": "my_tokenizer"
  131. }
  132. },
  133. "tokenizer": {
  134. "my_tokenizer": {
  135. "type": "standard",
  136. "max_token_length": 5
  137. }
  138. }
  139. }
  140. }
  141. }
  142. POST my-index-000001/_analyze
  143. {
  144. "analyzer": "my_analyzer",
  145. "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
  146. }
  147. ----------------------------
  148. /////////////////////
  149. [source,console-result]
  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. /////////////////////
  241. The above example produces the following terms:
  242. [source,text]
  243. ---------------------------
  244. [ The, 2, QUICK, Brown, Foxes, jumpe, d, over, the, lazy, dog's, bone ]
  245. ---------------------------