analyze.asciidoc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. [[indices-analyze]]
  2. == Analyze
  3. Performs the analysis process on a text and return the tokens breakdown
  4. of the text.
  5. Can be used without specifying an index against one of the many built in
  6. analyzers:
  7. [source,js]
  8. --------------------------------------------------
  9. curl -XGET 'localhost:9200/_analyze' -d '
  10. {
  11. "analyzer" : "standard",
  12. "text" : "this is a test"
  13. }'
  14. --------------------------------------------------
  15. If text parameter is provided as array of strings, it is analyzed as a multi-valued field.
  16. [source,js]
  17. --------------------------------------------------
  18. curl -XGET 'localhost:9200/_analyze' -d '
  19. {
  20. "analyzer" : "standard",
  21. "text" : ["this is a test", "the second text"]
  22. }'
  23. --------------------------------------------------
  24. Or by building a custom transient analyzer out of tokenizers,
  25. token filters and char filters. Token filters can use the shorter 'filter'
  26. parameter name:
  27. [source,js]
  28. --------------------------------------------------
  29. curl -XGET 'localhost:9200/_analyze' -d '
  30. {
  31. "tokenizer" : "keyword",
  32. "filter" : ["lowercase"],
  33. "text" : "this is a test"
  34. }'
  35. curl -XGET 'localhost:9200/_analyze' -d '
  36. {
  37. "tokenizer" : "keyword",
  38. "token_filter" : ["lowercase"],
  39. "char_filter" : ["html_strip"],
  40. "text" : "this is a <b>test</b>"
  41. }'
  42. --------------------------------------------------
  43. deprecated[5.0.0, Use `filter`/`token_filter`/`char_filter` instead of `filters`/`token_filters`/`char_filters`]
  44. It can also run against a specific index:
  45. [source,js]
  46. --------------------------------------------------
  47. curl -XGET 'localhost:9200/test/_analyze' -d '
  48. {
  49. "text" : "this is a test"
  50. }'
  51. --------------------------------------------------
  52. The above will run an analysis on the "this is a test" text, using the
  53. default index analyzer associated with the `test` index. An `analyzer`
  54. can also be provided to use a different analyzer:
  55. [source,js]
  56. --------------------------------------------------
  57. curl -XGET 'localhost:9200/test/_analyze' -d '
  58. {
  59. "analyzer" : "whitespace",
  60. "text : "this is a test"
  61. }'
  62. --------------------------------------------------
  63. Also, the analyzer can be derived based on a field mapping, for example:
  64. [source,js]
  65. --------------------------------------------------
  66. curl -XGET 'localhost:9200/test/_analyze' -d '
  67. {
  68. "field" : "obj1.field1",
  69. "text" : "this is a test"
  70. }'
  71. --------------------------------------------------
  72. Will cause the analysis to happen based on the analyzer configured in the
  73. mapping for `obj1.field1` (and if not, the default index analyzer).
  74. All parameters can also supplied as request parameters. For example:
  75. [source,js]
  76. --------------------------------------------------
  77. curl -XGET 'localhost:9200/_analyze?tokenizer=keyword&filter=lowercase&text=this+is+a+test'
  78. --------------------------------------------------
  79. For backwards compatibility, we also accept the text parameter as the body of the request,
  80. provided it doesn't start with `{` :
  81. [source,js]
  82. --------------------------------------------------
  83. curl -XGET 'localhost:9200/_analyze?tokenizer=keyword&token_filter=lowercase&char_filter=html_strip' -d 'this is a <b>test</b>'
  84. --------------------------------------------------
  85. === Explain Analyze
  86. If you want to get more advanced details, set `explain` to `true` (defaults to `false`). It will output all token attributes for each token.
  87. You can filter token attributes you want to output by setting `attributes` option.
  88. experimental[The format of the additional detail information is experimental and can change at any time]
  89. [source,js]
  90. --------------------------------------------------
  91. GET _analyze
  92. {
  93. "tokenizer" : "standard",
  94. "token_filter" : ["snowball"],
  95. "text" : "detailed output",
  96. "explain" : true,
  97. "attributes" : ["keyword"] <1>
  98. }
  99. --------------------------------------------------
  100. // CONSOLE
  101. <1> Set "keyword" to output "keyword" attribute only
  102. coming[2.0.0, body based parameters were added in 2.0.0]
  103. The request returns the following result:
  104. [source,js]
  105. --------------------------------------------------
  106. {
  107. "detail" : {
  108. "custom_analyzer" : true,
  109. "charfilters" : [ ],
  110. "tokenizer" : {
  111. "name" : "standard",
  112. "tokens" : [ {
  113. "token" : "detailed",
  114. "start_offset" : 0,
  115. "end_offset" : 8,
  116. "type" : "<ALPHANUM>",
  117. "position" : 0
  118. }, {
  119. "token" : "output",
  120. "start_offset" : 9,
  121. "end_offset" : 15,
  122. "type" : "<ALPHANUM>",
  123. "position" : 1
  124. } ]
  125. },
  126. "tokenfilters" : [ {
  127. "name" : "snowball",
  128. "tokens" : [ {
  129. "token" : "detail",
  130. "start_offset" : 0,
  131. "end_offset" : 8,
  132. "type" : "<ALPHANUM>",
  133. "position" : 0,
  134. "keyword" : false <1>
  135. }, {
  136. "token" : "output",
  137. "start_offset" : 9,
  138. "end_offset" : 15,
  139. "type" : "<ALPHANUM>",
  140. "position" : 1,
  141. "keyword" : false <1>
  142. } ]
  143. } ]
  144. }
  145. }
  146. --------------------------------------------------
  147. <1> Output only "keyword" attribute, since specify "attributes" in the request.