explain.asciidoc 4.7 KB

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