2013-08-28 19:24:34 -04:00
|
|
|
[[search-explain]]
|
|
|
|
== Explain API
|
|
|
|
|
|
|
|
The explain api computes a score explanation for a query and a specific
|
|
|
|
document. This can give useful feedback whether a document matches or
|
2013-10-13 10:46:56 -04:00
|
|
|
didn't match a specific query.
|
|
|
|
|
|
|
|
The `index` and `type` parameters expect a single index and a single
|
|
|
|
type respectively.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[float]
|
|
|
|
=== Usage
|
|
|
|
|
|
|
|
Full query example:
|
|
|
|
|
|
|
|
[source,js]
|
2016-08-01 08:09:54 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
curl -XGET 'localhost:9200/twitter/tweet/1/_explain' -d '{
|
|
|
|
"query" : {
|
2013-08-28 19:24:34 -04:00
|
|
|
"term" : { "message" : "search" }
|
2016-08-01 08:09:54 -04:00
|
|
|
}
|
|
|
|
}'
|
|
|
|
--------------------------------------------------
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
This will yield the following result:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
2016-08-01 08:09:54 -04:00
|
|
|
"matches" : true,
|
|
|
|
"explanation" : {
|
|
|
|
"value" : 0.15342641,
|
|
|
|
"description" : "fieldWeight(message:search in 0), product of:",
|
|
|
|
"details" : [ {
|
|
|
|
"value" : 1.0,
|
|
|
|
"description" : "tf(termFreq(message:search)=1)"
|
|
|
|
}, {
|
|
|
|
"value" : 0.30685282,
|
|
|
|
"description" : "idf(docFreq=1, maxDocs=1)"
|
|
|
|
}, {
|
|
|
|
"value" : 0.5,
|
|
|
|
"description" : "fieldNorm(field=message, doc=0)"
|
|
|
|
} ]
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
There is also a simpler way of specifying the query via the `q`
|
|
|
|
parameter. The specified `q` parameter value is then parsed as if the
|
|
|
|
`query_string` query was used. Example usage of the `q` parameter in the
|
|
|
|
explain api:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-08-01 08:09:54 -04:00
|
|
|
curl -XGET 'localhost:9200/twitter/tweet/1/_explain?q=message:search'
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
This will yield the same result as the previous request.
|
|
|
|
|
|
|
|
[float]
|
|
|
|
=== All parameters:
|
|
|
|
|
|
|
|
[horizontal]
|
2013-11-13 10:53:10 -05:00
|
|
|
`_source`::
|
|
|
|
|
2014-09-26 15:04:42 -04:00
|
|
|
Set to `true` to retrieve the `_source` of the document explained. You can also
|
2013-11-13 10:53:10 -05:00
|
|
|
retrieve part of the document by using `_source_include` & `_source_exclude` (see <<get-source-filtering,Get API>> for more details)
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
`fields`::
|
2013-11-13 10:53:10 -05:00
|
|
|
Allows to control which stored fields to return as part of the
|
|
|
|
document explained.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2013-10-13 10:46:56 -04:00
|
|
|
`routing`::
|
2013-08-28 19:24:34 -04:00
|
|
|
Controls the routing in the case the routing was used
|
|
|
|
during indexing.
|
|
|
|
|
2013-10-13 10:46:56 -04:00
|
|
|
`parent`::
|
|
|
|
Same effect as setting the routing parameter.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2013-10-13 10:46:56 -04:00
|
|
|
`preference`::
|
|
|
|
Controls on which shard the explain is executed.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2013-10-13 10:46:56 -04:00
|
|
|
`source`::
|
2013-08-28 19:24:34 -04:00
|
|
|
Allows the data of the request to be put in the query
|
2013-10-13 10:46:56 -04:00
|
|
|
string of the url.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2013-10-13 10:46:56 -04:00
|
|
|
`q`::
|
|
|
|
The query string (maps to the query_string query).
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2013-10-13 10:46:56 -04:00
|
|
|
`df`::
|
2013-08-28 19:24:34 -04:00
|
|
|
The default field to use when no field prefix is defined within
|
2013-10-13 10:46:56 -04:00
|
|
|
the query. Defaults to _all field.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2013-10-13 10:46:56 -04:00
|
|
|
`analyzer`::
|
2013-08-28 19:24:34 -04:00
|
|
|
The analyzer name to be used when analyzing the query
|
2013-10-13 10:46:56 -04:00
|
|
|
string. Defaults to the analyzer of the _all field.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2013-10-13 10:46:56 -04:00
|
|
|
`analyze_wildcard`::
|
2013-08-28 19:24:34 -04:00
|
|
|
Should wildcard and prefix queries be analyzed or
|
2013-10-13 10:46:56 -04:00
|
|
|
not. Defaults to false.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-03-13 15:51:41 -04:00
|
|
|
`lowercase_expanded_terms`::
|
|
|
|
Should terms be automatically lowercased
|
|
|
|
or not. Defaults to true.
|
|
|
|
|
2013-10-13 10:46:56 -04:00
|
|
|
`lenient`::
|
2013-08-28 19:24:34 -04:00
|
|
|
If set to true will cause format based failures (like
|
2013-10-13 10:46:56 -04:00
|
|
|
providing text to a numeric field) to be ignored. Defaults to false.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2013-10-13 10:46:56 -04:00
|
|
|
`default_operator`::
|
2013-08-28 19:24:34 -04:00
|
|
|
The default operator to be used, can be AND or
|
|
|
|
OR. Defaults to OR.
|