explain.asciidoc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. Imagine having indexed the following document:
  11. [source,js]
  12. ----------------------------------------
  13. PUT /twitter/tweet/1?refresh
  14. {
  15. "user": "kimchy",
  16. "message": "search"
  17. }
  18. ---------------------------------------
  19. // CONSOLE
  20. // TESTSETUP
  21. Full query example:
  22. [source,js]
  23. --------------------------------------
  24. GET /twitter/tweet/1/_explain
  25. {
  26. "query" : {
  27. "term" : { "message" : "search" }
  28. }
  29. }
  30. --------------------------------------
  31. // CONSOLE
  32. This will yield the following result:
  33. [source,js]
  34. --------------------------------------------------
  35. {
  36. "_index": "twitter",
  37. "_type": "tweet",
  38. "_id": "1",
  39. "matched": true,
  40. "explanation": {
  41. "value": 1.0,
  42. "description": "sum of:",
  43. "details": [
  44. {
  45. "value": 1.0,
  46. "description": "weight(message:search in 0) [PerFieldSimilarity], result of:",
  47. "details": [
  48. {
  49. "value": 1.0,
  50. "description": "fieldWeight in 0, product of:",
  51. "details": [
  52. {
  53. "value": 1.0,
  54. "description": "tf(freq=1.0), with freq of:",
  55. "details": [
  56. {
  57. "value": 1.0,
  58. "description": "termFreq=1.0",
  59. "details": []
  60. }
  61. ]
  62. },
  63. {
  64. "value": 1.0,
  65. "description": "idf(docFreq=1, docCount=1)",
  66. "details": []
  67. },
  68. {
  69. "value": 1.0,
  70. "description": "fieldNorm(doc=0)",
  71. "details": []
  72. }
  73. ]
  74. }
  75. ]
  76. },
  77. {
  78. "value": 0.0,
  79. "description": "match on required clause, product of:",
  80. "details": [
  81. {
  82. "value": 0.0,
  83. "description": "# clause",
  84. "details": []
  85. },
  86. {
  87. "value": 1.0,
  88. "description": "_type:tweet, product of:",
  89. "details": [
  90. {
  91. "value": 1.0,
  92. "description": "boost",
  93. "details": []
  94. },
  95. {
  96. "value": 1.0,
  97. "description": "queryNorm",
  98. "details": []
  99. }
  100. ]
  101. }
  102. ]
  103. }
  104. ]
  105. }
  106. }
  107. --------------------------------------------------
  108. // TESTRESPONSE
  109. There is also a simpler way of specifying the query via the `q`
  110. parameter. The specified `q` parameter value is then parsed as if the
  111. `query_string` query was used. Example usage of the `q` parameter in the
  112. explain api:
  113. [source,js]
  114. --------------------------------------------------
  115. GET /twitter/tweet/1/_explain?q=message:search
  116. --------------------------------------------------
  117. // CONSOLE
  118. This will yield the same result as the previous request.
  119. [float]
  120. === All parameters:
  121. [horizontal]
  122. `_source`::
  123. Set to `true` to retrieve the `_source` of the document explained. You can also
  124. retrieve part of the document by using `_source_include` & `_source_exclude` (see <<get-source-filtering,Get API>> for more details)
  125. `fields`::
  126. Allows to control which stored fields to return as part of the
  127. document explained.
  128. `routing`::
  129. Controls the routing in the case the routing was used
  130. during indexing.
  131. `parent`::
  132. Same effect as setting the routing parameter.
  133. `preference`::
  134. Controls on which shard the explain is executed.
  135. `source`::
  136. Allows the data of the request to be put in the query
  137. string of the url.
  138. `q`::
  139. The query string (maps to the query_string query).
  140. `df`::
  141. The default field to use when no field prefix is defined within
  142. the query. Defaults to _all field.
  143. `analyzer`::
  144. The analyzer name to be used when analyzing the query
  145. string. Defaults to the analyzer of the _all field.
  146. `analyze_wildcard`::
  147. Should wildcard and prefix queries be analyzed or
  148. not. Defaults to false.
  149. `lowercase_expanded_terms`::
  150. Should terms be automatically lowercased
  151. or not. Defaults to true.
  152. `lenient`::
  153. If set to true will cause format based failures (like
  154. providing text to a numeric field) to be ignored. Defaults to false.
  155. `default_operator`::
  156. The default operator to be used, can be AND or
  157. OR. Defaults to OR.