standard-analyzer.asciidoc 6.2 KB

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