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
|
|
|
--------------------------------------------------
|
2016-09-14 11:23:25 -04:00
|
|
|
GET /twitter/tweet/0/_explain
|
|
|
|
{
|
2016-08-01 08:09:54 -04:00
|
|
|
"query" : {
|
2016-09-14 11:23:25 -04:00
|
|
|
"match" : { "message" : "elasticsearch" }
|
2016-08-01 08:09:54 -04:00
|
|
|
}
|
2016-09-14 11:23:25 -04:00
|
|
|
}
|
2016-08-01 08:09:54 -04:00
|
|
|
--------------------------------------------------
|
2016-09-14 11:23:25 -04:00
|
|
|
// CONSOLE
|
|
|
|
// TEST[setup:twitter]
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
This will yield the following result:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
2016-11-29 12:40:31 -05:00
|
|
|
"_index": "twitter",
|
|
|
|
"_type": "tweet",
|
|
|
|
"_id": "0",
|
|
|
|
"matched": true,
|
|
|
|
"explanation": {
|
|
|
|
"value": 1.55077,
|
|
|
|
"description": "sum of:",
|
|
|
|
"details": [
|
|
|
|
{
|
|
|
|
"value": 1.55077,
|
|
|
|
"description": "weight(message:elasticsearch in 0) [PerFieldSimilarity], result of:",
|
|
|
|
"details": [
|
|
|
|
{
|
|
|
|
"value": 1.55077,
|
|
|
|
"description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
|
|
|
|
"details": [
|
|
|
|
{
|
|
|
|
"value": 1.3862944,
|
|
|
|
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
|
|
|
|
"details": [
|
|
|
|
{
|
|
|
|
"value": 1.0,
|
|
|
|
"description": "docFreq",
|
|
|
|
"details": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value": 5.0,
|
|
|
|
"description": "docCount",
|
|
|
|
"details": []
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value": 1.1186441,
|
|
|
|
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
|
|
|
|
"details": [
|
|
|
|
{
|
|
|
|
"value": 1.0,
|
|
|
|
"description": "termFreq=1.0",
|
|
|
|
"details": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value": 1.2,
|
|
|
|
"description": "parameter k1",
|
|
|
|
"details": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value": 0.75,
|
|
|
|
"description": "parameter b",
|
|
|
|
"details": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value": 5.4,
|
|
|
|
"description": "avgFieldLength",
|
|
|
|
"details": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value": 4.0,
|
|
|
|
"description": "fieldLength",
|
|
|
|
"details": []
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value": 0.0,
|
|
|
|
"description": "match on required clause, product of:",
|
|
|
|
"details": [
|
|
|
|
{
|
|
|
|
"value": 0.0,
|
|
|
|
"description": "# clause",
|
|
|
|
"details": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value": 1.0,
|
|
|
|
"description": "*:*, product of:",
|
|
|
|
"details": [
|
|
|
|
{
|
|
|
|
"value": 1.0,
|
|
|
|
"description": "boost",
|
|
|
|
"details": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value": 1.0,
|
|
|
|
"description": "queryNorm",
|
|
|
|
"details": []
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2016-08-01 08:09:54 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2016-09-14 11:23:25 -04:00
|
|
|
// TESTRESPONSE
|
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-09-14 11:23:25 -04:00
|
|
|
GET /twitter/tweet/0/_explain?q=message:search
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2016-09-14 11:23:25 -04:00
|
|
|
// CONSOLE
|
|
|
|
// TEST[setup:twitter]
|
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)
|
|
|
|
|
2016-09-13 14:54:41 -04:00
|
|
|
`stored_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
|
|
|
|
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.
|