standard-analyzer.asciidoc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. [[analysis-standard-analyzer]]
  2. === Standard analyzer
  3. ++++
  4. <titleabbrev>Standard</titleabbrev>
  5. ++++
  6. The `standard` analyzer is the default analyzer which is used if none is
  7. specified. It provides grammar based tokenization (based on the Unicode Text
  8. Segmentation algorithm, as specified in
  9. https://unicode.org/reports/tr29/[Unicode Standard Annex #29]) and works well
  10. for most languages.
  11. [discrete]
  12. === Example output
  13. [source,console]
  14. ---------------------------
  15. POST _analyze
  16. {
  17. "analyzer": "standard",
  18. "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
  19. }
  20. ---------------------------
  21. /////////////////////
  22. [source,console-result]
  23. ----------------------------
  24. {
  25. "tokens": [
  26. {
  27. "token": "the",
  28. "start_offset": 0,
  29. "end_offset": 3,
  30. "type": "<ALPHANUM>",
  31. "position": 0
  32. },
  33. {
  34. "token": "2",
  35. "start_offset": 4,
  36. "end_offset": 5,
  37. "type": "<NUM>",
  38. "position": 1
  39. },
  40. {
  41. "token": "quick",
  42. "start_offset": 6,
  43. "end_offset": 11,
  44. "type": "<ALPHANUM>",
  45. "position": 2
  46. },
  47. {
  48. "token": "brown",
  49. "start_offset": 12,
  50. "end_offset": 17,
  51. "type": "<ALPHANUM>",
  52. "position": 3
  53. },
  54. {
  55. "token": "foxes",
  56. "start_offset": 18,
  57. "end_offset": 23,
  58. "type": "<ALPHANUM>",
  59. "position": 4
  60. },
  61. {
  62. "token": "jumped",
  63. "start_offset": 24,
  64. "end_offset": 30,
  65. "type": "<ALPHANUM>",
  66. "position": 5
  67. },
  68. {
  69. "token": "over",
  70. "start_offset": 31,
  71. "end_offset": 35,
  72. "type": "<ALPHANUM>",
  73. "position": 6
  74. },
  75. {
  76. "token": "the",
  77. "start_offset": 36,
  78. "end_offset": 39,
  79. "type": "<ALPHANUM>",
  80. "position": 7
  81. },
  82. {
  83. "token": "lazy",
  84. "start_offset": 40,
  85. "end_offset": 44,
  86. "type": "<ALPHANUM>",
  87. "position": 8
  88. },
  89. {
  90. "token": "dog's",
  91. "start_offset": 45,
  92. "end_offset": 50,
  93. "type": "<ALPHANUM>",
  94. "position": 9
  95. },
  96. {
  97. "token": "bone",
  98. "start_offset": 51,
  99. "end_offset": 55,
  100. "type": "<ALPHANUM>",
  101. "position": 10
  102. }
  103. ]
  104. }
  105. ----------------------------
  106. /////////////////////
  107. The above sentence would produce the following terms:
  108. [source,text]
  109. ---------------------------
  110. [ the, 2, quick, brown, foxes, jumped, over, the, lazy, dog's, bone ]
  111. ---------------------------
  112. [discrete]
  113. === Configuration
  114. The `standard` analyzer accepts the following parameters:
  115. [horizontal]
  116. `max_token_length`::
  117. The maximum token length. If a token is seen that exceeds this length then
  118. it is split at `max_token_length` intervals. Defaults to `255`.
  119. `stopwords`::
  120. A pre-defined stop words list like `_english_` or an array containing a
  121. list of stop words. Defaults to `_none_`.
  122. `stopwords_path`::
  123. The path to a file containing stop words.
  124. See the <<analysis-stop-tokenfilter,Stop Token Filter>> for more information
  125. about stop word configuration.
  126. [discrete]
  127. === Example configuration
  128. In this example, we configure the `standard` analyzer to have a
  129. `max_token_length` of 5 (for demonstration purposes), and to use the
  130. pre-defined list of English stop words:
  131. [source,console]
  132. ----------------------------
  133. PUT my-index-000001
  134. {
  135. "settings": {
  136. "analysis": {
  137. "analyzer": {
  138. "my_english_analyzer": {
  139. "type": "standard",
  140. "max_token_length": 5,
  141. "stopwords": "_english_"
  142. }
  143. }
  144. }
  145. }
  146. }
  147. POST my-index-000001/_analyze
  148. {
  149. "analyzer": "my_english_analyzer",
  150. "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
  151. }
  152. ----------------------------
  153. /////////////////////
  154. [source,console-result]
  155. ----------------------------
  156. {
  157. "tokens": [
  158. {
  159. "token": "2",
  160. "start_offset": 4,
  161. "end_offset": 5,
  162. "type": "<NUM>",
  163. "position": 1
  164. },
  165. {
  166. "token": "quick",
  167. "start_offset": 6,
  168. "end_offset": 11,
  169. "type": "<ALPHANUM>",
  170. "position": 2
  171. },
  172. {
  173. "token": "brown",
  174. "start_offset": 12,
  175. "end_offset": 17,
  176. "type": "<ALPHANUM>",
  177. "position": 3
  178. },
  179. {
  180. "token": "foxes",
  181. "start_offset": 18,
  182. "end_offset": 23,
  183. "type": "<ALPHANUM>",
  184. "position": 4
  185. },
  186. {
  187. "token": "jumpe",
  188. "start_offset": 24,
  189. "end_offset": 29,
  190. "type": "<ALPHANUM>",
  191. "position": 5
  192. },
  193. {
  194. "token": "d",
  195. "start_offset": 29,
  196. "end_offset": 30,
  197. "type": "<ALPHANUM>",
  198. "position": 6
  199. },
  200. {
  201. "token": "over",
  202. "start_offset": 31,
  203. "end_offset": 35,
  204. "type": "<ALPHANUM>",
  205. "position": 7
  206. },
  207. {
  208. "token": "lazy",
  209. "start_offset": 40,
  210. "end_offset": 44,
  211. "type": "<ALPHANUM>",
  212. "position": 9
  213. },
  214. {
  215. "token": "dog's",
  216. "start_offset": 45,
  217. "end_offset": 50,
  218. "type": "<ALPHANUM>",
  219. "position": 10
  220. },
  221. {
  222. "token": "bone",
  223. "start_offset": 51,
  224. "end_offset": 55,
  225. "type": "<ALPHANUM>",
  226. "position": 11
  227. }
  228. ]
  229. }
  230. ----------------------------
  231. /////////////////////
  232. The above example produces the following terms:
  233. [source,text]
  234. ---------------------------
  235. [ 2, quick, brown, foxes, jumpe, d, over, lazy, dog's, bone ]
  236. ---------------------------
  237. [discrete]
  238. === Definition
  239. The `standard` analyzer consists of:
  240. Tokenizer::
  241. * <<analysis-standard-tokenizer,Standard Tokenizer>>
  242. Token Filters::
  243. * <<analysis-lowercase-tokenfilter,Lower Case Token Filter>>
  244. * <<analysis-stop-tokenfilter,Stop Token Filter>> (disabled by default)
  245. If you need to customize the `standard` analyzer beyond the configuration
  246. parameters then you need to recreate it as a `custom` analyzer and modify
  247. it, usually by adding token filters. This would recreate the built-in
  248. `standard` analyzer and you can use it as a starting point:
  249. [source,console]
  250. ----------------------------------------------------
  251. PUT /standard_example
  252. {
  253. "settings": {
  254. "analysis": {
  255. "analyzer": {
  256. "rebuilt_standard": {
  257. "tokenizer": "standard",
  258. "filter": [
  259. "lowercase" <1>
  260. ]
  261. }
  262. }
  263. }
  264. }
  265. }
  266. ----------------------------------------------------
  267. // TEST[s/\n$/\nstartyaml\n - compare_analyzers: {index: standard_example, first: standard, second: rebuilt_standard}\nendyaml\n/]
  268. <1> You'd add any token filters after `lowercase`.