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]
|
|
|
|
--------------------------------------------------
|
|
|
|
curl -XGET 'localhost:9200/twitter/tweet/1/_explain' -d '{
|
|
|
|
"query" : {
|
|
|
|
"term" : { "message" : "search" }
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
This will yield the following result:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"ok" : true,
|
|
|
|
"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)"
|
|
|
|
} ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
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]
|
|
|
|
--------------------------------------------------
|
|
|
|
curl -XGET 'localhost:9200/twitter/tweet/1/_explain?q=message:search'
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
This will yield the same result as the previous request.
|
|
|
|
|
|
|
|
[float]
|
|
|
|
=== All parameters:
|
|
|
|
|
|
|
|
[horizontal]
|
|
|
|
`fields`::
|
|
|
|
Allows to control which fields to return as part of the
|
2013-10-13 10:46:56 -04:00
|
|
|
document explained (support `_source` for the full document).
|
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
|
|
|
|
2013-10-13 10:46:56 -04:00
|
|
|
`lowercase_expanded_terms`::
|
2013-08-28 19:24:34 -04:00
|
|
|
Should terms be automatically lowercased
|
2013-10-13 10:46:56 -04:00
|
|
|
or not. Defaults to true.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
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.
|