explain.asciidoc 4.6 KB

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