|
1 | 1 | [[query-dsl-dis-max-query]] |
2 | | -=== Dis Max Query |
3 | | - |
4 | | -A query that generates the union of documents produced by its |
5 | | -subqueries, and that scores each document with the maximum score for |
6 | | -that document as produced by any subquery, plus a tie breaking increment |
7 | | -for any additional matching subqueries. |
8 | | - |
9 | | -This is useful when searching for a word in multiple fields with |
10 | | -different boost factors (so that the fields cannot be combined |
11 | | -equivalently into a single search field). We want the primary score to |
12 | | -be the one associated with the highest boost, not the sum of the field |
13 | | -scores (as Boolean Query would give). If the query is "albino elephant" |
14 | | -this ensures that "albino" matching one field and "elephant" matching |
15 | | -another gets a higher score than "albino" matching both fields. To get |
16 | | -this result, use both Boolean Query and DisjunctionMax Query: for each |
17 | | -term a DisjunctionMaxQuery searches for it in each field, while the set |
18 | | -of these DisjunctionMaxQuery's is combined into a BooleanQuery. |
19 | | - |
20 | | -The tie breaker capability allows results that include the same term in |
21 | | -multiple fields to be judged better than results that include this term |
22 | | -in only the best of those multiple fields, without confusing this with |
23 | | -the better case of two different terms in the multiple fields.The |
24 | | -default `tie_breaker` is `0.0`. |
25 | | - |
26 | | -This query maps to Lucene `DisjunctionMaxQuery`. |
| 2 | +=== Disjunction Max Query |
| 3 | + |
| 4 | +Returns documents matching one or more wrapped queries, called query clauses or |
| 5 | +clauses. |
| 6 | + |
| 7 | +If a returned document matches multiple query clauses, the `dis_max` query |
| 8 | +assigns the document the highest relevance score from any matching clause, plus |
| 9 | +a tie breaking increment for any additional matching subqueries. |
| 10 | + |
| 11 | +You can use the `dis_max` to search for a term in fields mapped with different |
| 12 | +<<mapping-boost,boost>> factors. |
| 13 | + |
| 14 | +[[query-dsl-dis-max-query-ex-request]] |
| 15 | +==== Example request |
27 | 16 |
|
28 | 17 | [source,js] |
29 | | --------------------------------------------------- |
| 18 | +---- |
30 | 19 | GET /_search |
31 | 20 | { |
32 | 21 | "query": { |
33 | 22 | "dis_max" : { |
34 | | - "tie_breaker" : 0.7, |
35 | | - "boost" : 1.2, |
36 | 23 | "queries" : [ |
37 | | - { |
38 | | - "term" : { "age" : 34 } |
39 | | - }, |
40 | | - { |
41 | | - "term" : { "age" : 35 } |
42 | | - } |
43 | | - ] |
| 24 | + { "term" : { "title" : "Quick pets" }}, |
| 25 | + { "term" : { "body" : "Quick pets" }} |
| 26 | + ], |
| 27 | + "tie_breaker" : 0.7 |
44 | 28 | } |
45 | 29 | } |
46 | 30 | } |
47 | | --------------------------------------------------- |
| 31 | +---- |
48 | 32 | // CONSOLE |
| 33 | + |
| 34 | +[[query-dsl-dis-max-query-top-level-params]] |
| 35 | +==== Top-level parameters for `dis_max` |
| 36 | + |
| 37 | +`queries` (Required):: |
| 38 | +(array of query objects) Contains one or more query clauses. Returned documents |
| 39 | +**must match one or more** of these queries. If a document matches multiple |
| 40 | +queries, {es} uses the highest <<query-filter-context, relevance score>>. |
| 41 | + |
| 42 | +`tie_breaker` (Optional):: |
| 43 | ++ |
| 44 | +-- |
| 45 | +(float) Floating point number between `0` and `1.0` used to increase the |
| 46 | +<<query-filter-context, relevance scores>> of documents matching multiple query |
| 47 | +clauses. Defaults to `0.0`. |
| 48 | + |
| 49 | +You can use the `tie_breaker` value to assign higher relevance scores to |
| 50 | +documents that contain the same term in multiple fields than documents that |
| 51 | +contain this term in only the best of those multiple fields, without confusing |
| 52 | +this with the better case of two different terms in the multiple fields. |
| 53 | + |
| 54 | +If a document matches multiple clauses, the `dis_max` query calculates the |
| 55 | +relevance score for the document as follows: |
| 56 | + |
| 57 | +. Take the relevance score from a matching clause with the highest score. |
| 58 | +. Multiply the score from any other matching clauses by the `tie_breaker` value. |
| 59 | +. Add the highest score to the multiplied scores. |
| 60 | + |
| 61 | +If the `tie_breaker` value is greater than `0.0`, all matching clauses count, |
| 62 | +but the clause with the highest score counts most. |
| 63 | +-- |
0 commit comments