explain.asciidoc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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/_doc/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":"_doc",
  28. "_id":"0",
  29. "matched":true,
  30. "explanation":{
  31. "value":1.6943597,
  32. "description":"weight(message:elasticsearch in 0) [PerFieldSimilarity], result of:",
  33. "details":[
  34. {
  35. "value":1.6943597,
  36. "description":"score(freq=1.0), product of:",
  37. "details":[
  38. {
  39. "value":2.2,
  40. "description":"scaling factor, k1 + 1",
  41. "details":[]
  42. },
  43. {
  44. "value":1.3862944,
  45. "description":"idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:",
  46. "details":[
  47. {
  48. "value":1,
  49. "description":"n, number of documents containing term",
  50. "details":[]
  51. },
  52. {
  53. "value":5,
  54. "description":"N, total number of documents with field",
  55. "details":[]
  56. }
  57. ]
  58. },
  59. {
  60. "value":0.5555555,
  61. "description":"tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
  62. "details":[
  63. {
  64. "value":1.0,
  65. "description":"freq, occurrences of term within document",
  66. "details":[]
  67. },
  68. {
  69. "value":1.2,
  70. "description":"k1, term saturation parameter",
  71. "details":[]
  72. },
  73. {
  74. "value":0.75,
  75. "description":"b, length normalization parameter",
  76. "details":[]
  77. },
  78. {
  79. "value":3.0,
  80. "description":"dl, length of field",
  81. "details":[]
  82. },
  83. {
  84. "value":5.4,
  85. "description":"avgdl, average length of field",
  86. "details":[]
  87. }
  88. ]
  89. }
  90. ]
  91. }
  92. ]
  93. }
  94. }
  95. --------------------------------------------------
  96. // TESTRESPONSE
  97. There is also a simpler way of specifying the query via the `q`
  98. parameter. The specified `q` parameter value is then parsed as if the
  99. `query_string` query was used. Example usage of the `q` parameter in the
  100. explain api:
  101. [source,js]
  102. --------------------------------------------------
  103. GET /twitter/_doc/0/_explain?q=message:search
  104. --------------------------------------------------
  105. // CONSOLE
  106. // TEST[setup:twitter]
  107. This will yield the same result as the previous request.
  108. [float]
  109. === All parameters:
  110. [horizontal]
  111. `_source`::
  112. Set to `true` to retrieve the `_source` of the document explained. You can also
  113. retrieve part of the document by using `_source_include` & `_source_exclude` (see <<get-source-filtering,Get API>> for more details)
  114. `stored_fields`::
  115. Allows to control which stored fields to return as part of the
  116. document explained.
  117. `routing`::
  118. Controls the routing in the case the routing was used
  119. during indexing.
  120. `parent`::
  121. Same effect as setting the routing parameter.
  122. `preference`::
  123. Controls on which shard the explain is executed.
  124. `source`::
  125. Allows the data of the request to be put in the query
  126. string of the url.
  127. `q`::
  128. The query string (maps to the query_string query).
  129. `df`::
  130. The default field to use when no field prefix is defined within
  131. the query.
  132. `analyzer`::
  133. The analyzer name to be used when analyzing the query
  134. string. Defaults to the default search analyzer.
  135. `analyze_wildcard`::
  136. Should wildcard and prefix queries be analyzed or
  137. not. Defaults to false.
  138. `lenient`::
  139. If set to true will cause format based failures (like
  140. providing text to a numeric field) to be ignored. Defaults to false.
  141. `default_operator`::
  142. The default operator to be used, can be AND or
  143. OR. Defaults to OR.