explain.asciidoc 4.8 KB

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