explain.asciidoc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. [[search-explain]]
  2. == Explain API
  3. The explain api computes a score explanation for a query and a specific
  4. document. This can give useful feedback whether a document matches or
  5. didn't match a specific query.
  6. The `index` and `type` parameters expect a single index and a single
  7. type respectively.
  8. [float]
  9. === Usage
  10. Full query example:
  11. [source,js]
  12. --------------------------------------------------
  13. GET /twitter/tweet/0/_explain
  14. {
  15. "query" : {
  16. "match" : { "message" : "elasticsearch" }
  17. }
  18. }
  19. --------------------------------------------------
  20. // CONSOLE
  21. // TEST[setup:twitter]
  22. This will yield the following result:
  23. [source,js]
  24. --------------------------------------------------
  25. {
  26. "_index": "twitter",
  27. "_type": "tweet",
  28. "_id": "0",
  29. "matched": true,
  30. "explanation": {
  31. "value": 1.55077,
  32. "description": "sum of:",
  33. "details": [
  34. {
  35. "value": 1.55077,
  36. "description": "weight(message:elasticsearch in 0) [PerFieldSimilarity], result of:",
  37. "details": [
  38. {
  39. "value": 1.55077,
  40. "description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
  41. "details": [
  42. {
  43. "value": 1.3862944,
  44. "description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
  45. "details": [
  46. {
  47. "value": 1.0,
  48. "description": "docFreq",
  49. "details": []
  50. },
  51. {
  52. "value": 5.0,
  53. "description": "docCount",
  54. "details": []
  55. }
  56. ]
  57. },
  58. {
  59. "value": 1.1186441,
  60. "description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
  61. "details": [
  62. {
  63. "value": 1.0,
  64. "description": "termFreq=1.0",
  65. "details": []
  66. },
  67. {
  68. "value": 1.2,
  69. "description": "parameter k1",
  70. "details": []
  71. },
  72. {
  73. "value": 0.75,
  74. "description": "parameter b",
  75. "details": []
  76. },
  77. {
  78. "value": 5.4,
  79. "description": "avgFieldLength",
  80. "details": []
  81. },
  82. {
  83. "value": 4.0,
  84. "description": "fieldLength",
  85. "details": []
  86. }
  87. ]
  88. }
  89. ]
  90. }
  91. ]
  92. },
  93. {
  94. "value": 0.0,
  95. "description": "match on required clause, product of:",
  96. "details": [
  97. {
  98. "value": 0.0,
  99. "description": "# clause",
  100. "details": []
  101. },
  102. {
  103. "value": 1.0,
  104. "description": "*:*, product of:",
  105. "details": [
  106. {
  107. "value": 1.0,
  108. "description": "boost",
  109. "details": []
  110. },
  111. {
  112. "value": 1.0,
  113. "description": "queryNorm",
  114. "details": []
  115. }
  116. ]
  117. }
  118. ]
  119. }
  120. ]
  121. }
  122. }
  123. --------------------------------------------------
  124. // TESTRESPONSE
  125. There is also a simpler way of specifying the query via the `q`
  126. parameter. The specified `q` parameter value is then parsed as if the
  127. `query_string` query was used. Example usage of the `q` parameter in the
  128. explain api:
  129. [source,js]
  130. --------------------------------------------------
  131. GET /twitter/tweet/0/_explain?q=message:search
  132. --------------------------------------------------
  133. // CONSOLE
  134. // TEST[setup:twitter]
  135. This will yield the same result as the previous request.
  136. [float]
  137. === All parameters:
  138. [horizontal]
  139. `_source`::
  140. Set to `true` to retrieve the `_source` of the document explained. You can also
  141. retrieve part of the document by using `_source_include` & `_source_exclude` (see <<get-source-filtering,Get API>> for more details)
  142. `stored_fields`::
  143. Allows to control which stored fields to return as part of the
  144. document explained.
  145. `routing`::
  146. Controls the routing in the case the routing was used
  147. during indexing.
  148. `parent`::
  149. Same effect as setting the routing parameter.
  150. `preference`::
  151. Controls on which shard the explain is executed.
  152. `source`::
  153. Allows the data of the request to be put in the query
  154. string of the url.
  155. `q`::
  156. The query string (maps to the query_string query).
  157. `df`::
  158. The default field to use when no field prefix is defined within
  159. the query. Defaults to _all field.
  160. `analyzer`::
  161. The analyzer name to be used when analyzing the query
  162. string. Defaults to the analyzer of the _all field.
  163. `analyze_wildcard`::
  164. Should wildcard and prefix queries be analyzed or
  165. not. Defaults to false.
  166. `lenient`::
  167. If set to true will cause format based failures (like
  168. providing text to a numeric field) to be ignored. Defaults to false.
  169. `default_operator`::
  170. The default operator to be used, can be AND or
  171. OR. Defaults to OR.