explain.asciidoc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. curl -XGET 'localhost:9200/twitter/tweet/1/_explain' -d '{
  14. "query" : {
  15. "term" : { "message" : "search" }
  16. }
  17. }'
  18. --------------------------------------------------
  19. This will yield the following result:
  20. [source,js]
  21. --------------------------------------------------
  22. {
  23. "matches" : true,
  24. "explanation" : {
  25. "value" : 0.15342641,
  26. "description" : "fieldWeight(message:search in 0), product of:",
  27. "details" : [ {
  28. "value" : 1.0,
  29. "description" : "tf(termFreq(message:search)=1)"
  30. }, {
  31. "value" : 0.30685282,
  32. "description" : "idf(docFreq=1, maxDocs=1)"
  33. }, {
  34. "value" : 0.5,
  35. "description" : "fieldNorm(field=message, doc=0)"
  36. } ]
  37. }
  38. }
  39. --------------------------------------------------
  40. There is also a simpler way of specifying the query via the `q`
  41. parameter. The specified `q` parameter value is then parsed as if the
  42. `query_string` query was used. Example usage of the `q` parameter in the
  43. explain api:
  44. [source,js]
  45. --------------------------------------------------
  46. curl -XGET 'localhost:9200/twitter/tweet/1/_explain?q=message:search'
  47. --------------------------------------------------
  48. This will yield the same result as the previous request.
  49. [float]
  50. === All parameters:
  51. [horizontal]
  52. `_source`::
  53. Set to `true` to retrieve the `_source` of the document explained. You can also
  54. retrieve part of the document by using `_source_include` & `_source_exclude` (see <<get-source-filtering,Get API>> for more details)
  55. `fields`::
  56. Allows to control which stored fields to return as part of the
  57. document explained.
  58. `routing`::
  59. Controls the routing in the case the routing was used
  60. during indexing.
  61. `parent`::
  62. Same effect as setting the routing parameter.
  63. `preference`::
  64. Controls on which shard the explain is executed.
  65. `source`::
  66. Allows the data of the request to be put in the query
  67. string of the url.
  68. `q`::
  69. The query string (maps to the query_string query).
  70. `df`::
  71. The default field to use when no field prefix is defined within
  72. the query. Defaults to _all field.
  73. `analyzer`::
  74. The analyzer name to be used when analyzing the query
  75. string. Defaults to the analyzer of the _all field.
  76. `analyze_wildcard`::
  77. Should wildcard and prefix queries be analyzed or
  78. not. Defaults to false.
  79. `lowercase_expanded_terms`::
  80. Should terms be automatically lowercased
  81. or not. Defaults to true.
  82. `lenient`::
  83. If set to true will cause format based failures (like
  84. providing text to a numeric field) to be ignored. Defaults to false.
  85. `default_operator`::
  86. The default operator to be used, can be AND or
  87. OR. Defaults to OR.