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
|
|
|
|
|
2016-05-19 06:17:13 -04:00
|
|
|
Imagine having indexed the following document:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
----------------------------------------
|
|
|
|
PUT /twitter/tweet/1?refresh
|
|
|
|
{
|
|
|
|
"user": "kimchy",
|
|
|
|
"message": "search"
|
|
|
|
}
|
|
|
|
---------------------------------------
|
|
|
|
// CONSOLE
|
|
|
|
// TESTSETUP
|
|
|
|
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
Full query example:
|
|
|
|
|
|
|
|
[source,js]
|
2016-05-19 06:17:13 -04:00
|
|
|
--------------------------------------
|
|
|
|
GET /twitter/tweet/1/_explain
|
|
|
|
{
|
|
|
|
"query" : {
|
2013-08-28 19:24:34 -04:00
|
|
|
"term" : { "message" : "search" }
|
2016-05-19 06:17:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------
|
|
|
|
// CONSOLE
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
This will yield the following result:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
2016-05-19 06:17:13 -04:00
|
|
|
"_index": "twitter",
|
|
|
|
"_type": "tweet",
|
|
|
|
"_id": "1",
|
|
|
|
"matched": true,
|
|
|
|
"explanation": {
|
2016-07-27 08:30:14 -04:00
|
|
|
"value": 0.2876821,
|
2016-05-19 06:17:13 -04:00
|
|
|
"description": "sum of:",
|
|
|
|
"details": [
|
|
|
|
{
|
2016-07-27 08:30:14 -04:00
|
|
|
"value": 0.2876821,
|
2016-05-19 06:17:13 -04:00
|
|
|
"description": "weight(message:search in 0) [PerFieldSimilarity], result of:",
|
|
|
|
"details": [
|
|
|
|
{
|
2016-07-27 08:30:14 -04:00
|
|
|
"value": 0.2876821,
|
|
|
|
"description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
|
2016-05-19 06:17:13 -04:00
|
|
|
"details": [
|
|
|
|
{
|
2016-07-27 08:30:14 -04:00
|
|
|
"value": 0.2876821,
|
2016-05-19 06:17:13 -04:00
|
|
|
"description": "idf(docFreq=1, docCount=1)",
|
2016-07-27 08:30:14 -04:00
|
|
|
"details": [ ]
|
2016-05-19 06:17:13 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"value": 1.0,
|
2016-07-27 08:30:14 -04:00
|
|
|
"description": "tfNorm, computed 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" : 1.0,
|
|
|
|
"description" : "avgFieldLength",
|
|
|
|
"details" : [ ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value" : 1.0,
|
|
|
|
"description" : "fieldLength",
|
|
|
|
"details" : [ ]
|
|
|
|
}
|
|
|
|
]
|
2016-05-19 06:17:13 -04:00
|
|
|
}
|
2016-07-27 08:30:14 -04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value" : 0.0,
|
|
|
|
"description" : "match on required clause, product of:",
|
|
|
|
"details" : [
|
|
|
|
{
|
|
|
|
"value" : 0.0,
|
|
|
|
"description" : "# clause",
|
|
|
|
"details" : [ ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value" : 1.0,
|
|
|
|
"description" : "_type:tweet, product of:",
|
|
|
|
"details" : [
|
2016-05-19 06:17:13 -04:00
|
|
|
{
|
2016-07-27 08:30:14 -04:00
|
|
|
"value" : 1.0,
|
|
|
|
"description" : "boost",
|
|
|
|
"details" : [ ]
|
2016-05-19 06:17:13 -04:00
|
|
|
},
|
|
|
|
{
|
2016-07-27 08:30:14 -04:00
|
|
|
"value" : 1.0,
|
|
|
|
"description" : "queryNorm",
|
|
|
|
"details" : [ ]
|
2016-05-19 06:17:13 -04:00
|
|
|
}
|
2016-07-27 08:30:14 -04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2016-05-19 06:17:13 -04:00
|
|
|
}
|
2016-07-27 08:30:14 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2016-05-19 06:17:13 -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-05-19 06:17:13 -04:00
|
|
|
GET /twitter/tweet/1/_explain?q=message:search
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2016-05-19 06:17:13 -04:00
|
|
|
// CONSOLE
|
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.
|