2013-08-28 19:24:34 -04:00
|
|
|
[[query-dsl-dis-max-query]]
|
2019-07-18 10:18:11 -04:00
|
|
|
=== Disjunction max query
|
|
|
|
++++
|
|
|
|
<titleabbrev>Disjunction max</titleabbrev>
|
|
|
|
++++
|
2019-07-03 08:55:50 -04:00
|
|
|
|
|
|
|
Returns documents matching one or more wrapped queries, called query clauses or
|
|
|
|
clauses.
|
|
|
|
|
|
|
|
If a returned document matches multiple query clauses, the `dis_max` query
|
|
|
|
assigns the document the highest relevance score from any matching clause, plus
|
|
|
|
a tie breaking increment for any additional matching subqueries.
|
|
|
|
|
|
|
|
You can use the `dis_max` to search for a term in fields mapped with different
|
|
|
|
<<mapping-boost,boost>> factors.
|
|
|
|
|
|
|
|
[[query-dsl-dis-max-query-ex-request]]
|
|
|
|
==== Example request
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2019-07-03 08:55:50 -04:00
|
|
|
----
|
2016-05-24 05:58:43 -04:00
|
|
|
GET /_search
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"query": {
|
|
|
|
"dis_max": {
|
|
|
|
"queries": [
|
|
|
|
{ "term": { "title": "Quick pets" } },
|
|
|
|
{ "term": { "body": "Quick pets" } }
|
|
|
|
],
|
|
|
|
"tie_breaker": 0.7
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
|
|
|
}
|
2019-07-03 08:55:50 -04:00
|
|
|
----
|
|
|
|
|
|
|
|
[[query-dsl-dis-max-query-top-level-params]]
|
|
|
|
==== Top-level parameters for `dis_max`
|
|
|
|
|
2019-07-31 14:18:22 -04:00
|
|
|
`queries`::
|
|
|
|
(Required, array of query objects) Contains one or more query clauses. Returned
|
|
|
|
documents **must match one or more** of these queries. If a document matches
|
|
|
|
multiple queries, {es} uses the highest <<query-filter-context, relevance
|
|
|
|
score>>.
|
2019-07-03 08:55:50 -04:00
|
|
|
|
2019-07-31 14:18:22 -04:00
|
|
|
`tie_breaker`::
|
2019-07-03 08:55:50 -04:00
|
|
|
+
|
|
|
|
--
|
2019-07-31 14:18:22 -04:00
|
|
|
(Optional, float) Floating point number between `0` and `1.0` used to increase
|
2019-08-02 14:15:12 -04:00
|
|
|
the <<relevance-scores,relevance scores>> of documents matching multiple
|
2019-07-31 14:18:22 -04:00
|
|
|
query clauses. Defaults to `0.0`.
|
2019-07-03 08:55:50 -04:00
|
|
|
|
|
|
|
You can use the `tie_breaker` value to assign higher relevance scores to
|
|
|
|
documents that contain the same term in multiple fields than documents that
|
|
|
|
contain this term in only the best of those multiple fields, without confusing
|
|
|
|
this with the better case of two different terms in the multiple fields.
|
|
|
|
|
|
|
|
If a document matches multiple clauses, the `dis_max` query calculates the
|
|
|
|
relevance score for the document as follows:
|
|
|
|
|
|
|
|
. Take the relevance score from a matching clause with the highest score.
|
|
|
|
. Multiply the score from any other matching clauses by the `tie_breaker` value.
|
|
|
|
. Add the highest score to the multiplied scores.
|
|
|
|
|
|
|
|
If the `tie_breaker` value is greater than `0.0`, all matching clauses count,
|
|
|
|
but the clause with the highest score counts most.
|
|
|
|
--
|