explain.asciidoc 2.8 KB

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