standard-analyzer.asciidoc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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,console]
  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. /////////////////////
  19. [source,console-result]
  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. /////////////////////
  104. The above sentence would produce the following terms:
  105. [source,text]
  106. ---------------------------
  107. [ the, 2, quick, brown, foxes, jumped, over, the, lazy, dog's, bone ]
  108. ---------------------------
  109. [float]
  110. === Configuration
  111. The `standard` analyzer accepts the following parameters:
  112. [horizontal]
  113. `max_token_length`::
  114. The maximum token length. If a token is seen that exceeds this length then
  115. it is split at `max_token_length` intervals. Defaults to `255`.
  116. `stopwords`::
  117. A pre-defined stop words list like `_english_` or an array containing a
  118. list of stop words. Defaults to `_none_`.
  119. `stopwords_path`::
  120. The path to a file containing stop words.
  121. See the <<analysis-stop-tokenfilter,Stop Token Filter>> for more information
  122. about stop word configuration.
  123. [float]
  124. === Example configuration
  125. In this example, we configure the `standard` analyzer to have a
  126. `max_token_length` of 5 (for demonstration purposes), and to use the
  127. pre-defined list of English stop words:
  128. [source,console]
  129. ----------------------------
  130. PUT my_index
  131. {
  132. "settings": {
  133. "analysis": {
  134. "analyzer": {
  135. "my_english_analyzer": {
  136. "type": "standard",
  137. "max_token_length": 5,
  138. "stopwords": "_english_"
  139. }
  140. }
  141. }
  142. }
  143. }
  144. POST my_index/_analyze
  145. {
  146. "analyzer": "my_english_analyzer",
  147. "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
  148. }
  149. ----------------------------
  150. /////////////////////
  151. [source,console-result]
  152. ----------------------------
  153. {
  154. "tokens": [
  155. {
  156. "token": "2",
  157. "start_offset": 4,
  158. "end_offset": 5,
  159. "type": "<NUM>",
  160. "position": 1
  161. },
  162. {
  163. "token": "quick",
  164. "start_offset": 6,
  165. "end_offset": 11,
  166. "type": "<ALPHANUM>",
  167. "position": 2
  168. },
  169. {
  170. "token": "brown",
  171. "start_offset": 12,
  172. "end_offset": 17,
  173. "type": "<ALPHANUM>",
  174. "position": 3
  175. },
  176. {
  177. "token": "foxes",
  178. "start_offset": 18,
  179. "end_offset": 23,
  180. "type": "<ALPHANUM>",
  181. "position": 4
  182. },
  183. {
  184. "token": "jumpe",
  185. "start_offset": 24,
  186. "end_offset": 29,
  187. "type": "<ALPHANUM>",
  188. "position": 5
  189. },
  190. {
  191. "token": "d",
  192. "start_offset": 29,
  193. "end_offset": 30,
  194. "type": "<ALPHANUM>",
  195. "position": 6
  196. },
  197. {
  198. "token": "over",
  199. "start_offset": 31,
  200. "end_offset": 35,
  201. "type": "<ALPHANUM>",
  202. "position": 7
  203. },
  204. {
  205. "token": "lazy",
  206. "start_offset": 40,
  207. "end_offset": 44,
  208. "type": "<ALPHANUM>",
  209. "position": 9
  210. },
  211. {
  212. "token": "dog's",
  213. "start_offset": 45,
  214. "end_offset": 50,
  215. "type": "<ALPHANUM>",
  216. "position": 10
  217. },
  218. {
  219. "token": "bone",
  220. "start_offset": 51,
  221. "end_offset": 55,
  222. "type": "<ALPHANUM>",
  223. "position": 11
  224. }
  225. ]
  226. }
  227. ----------------------------
  228. /////////////////////
  229. The above example produces the following terms:
  230. [source,text]
  231. ---------------------------
  232. [ 2, quick, brown, foxes, jumpe, d, over, lazy, dog's, bone ]
  233. ---------------------------
  234. [float]
  235. === Definition
  236. The `standard` analyzer consists of:
  237. Tokenizer::
  238. * <<analysis-standard-tokenizer,Standard Tokenizer>>
  239. Token Filters::
  240. * <<analysis-lowercase-tokenfilter,Lower Case Token Filter>>
  241. * <<analysis-stop-tokenfilter,Stop Token Filter>> (disabled by default)
  242. If you need to customize the `standard` analyzer beyond the configuration
  243. parameters then you need to recreate it as a `custom` analyzer and modify
  244. it, usually by adding token filters. This would recreate the built-in
  245. `standard` analyzer and you can use it as a starting point:
  246. [source,console]
  247. ----------------------------------------------------
  248. PUT /standard_example
  249. {
  250. "settings": {
  251. "analysis": {
  252. "analyzer": {
  253. "rebuilt_standard": {
  254. "tokenizer": "standard",
  255. "filter": [
  256. "lowercase" <1>
  257. ]
  258. }
  259. }
  260. }
  261. }
  262. }
  263. ----------------------------------------------------
  264. // TEST[s/\n$/\nstartyaml\n - compare_analyzers: {index: standard_example, first: standard, second: rebuilt_standard}\nendyaml\n/]
  265. <1> You'd add any token filters after `lowercase`.