dis-max-query.asciidoc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. [[query-dsl-dis-max-query]]
  2. === Disjunction Max Query
  3. Returns documents matching one or more wrapped queries, called query clauses or
  4. clauses.
  5. If a returned document matches multiple query clauses, the `dis_max` query
  6. assigns the document the highest relevance score from any matching clause, plus
  7. a tie breaking increment for any additional matching subqueries.
  8. You can use the `dis_max` to search for a term in fields mapped with different
  9. <<mapping-boost,boost>> factors.
  10. [[query-dsl-dis-max-query-ex-request]]
  11. ==== Example request
  12. [source,js]
  13. ----
  14. GET /_search
  15. {
  16. "query": {
  17. "dis_max" : {
  18. "queries" : [
  19. { "term" : { "title" : "Quick pets" }},
  20. { "term" : { "body" : "Quick pets" }}
  21. ],
  22. "tie_breaker" : 0.7
  23. }
  24. }
  25. }
  26. ----
  27. // CONSOLE
  28. [[query-dsl-dis-max-query-top-level-params]]
  29. ==== Top-level parameters for `dis_max`
  30. `queries` (Required)::
  31. (array of query objects) Contains one or more query clauses. Returned documents
  32. **must match one or more** of these queries. If a document matches multiple
  33. queries, {es} uses the highest <<query-filter-context, relevance score>>.
  34. `tie_breaker` (Optional)::
  35. +
  36. --
  37. (float) Floating point number between `0` and `1.0` used to increase the
  38. <<query-filter-context, relevance scores>> of documents matching multiple query
  39. clauses. Defaults to `0.0`.
  40. You can use the `tie_breaker` value to assign higher relevance scores to
  41. documents that contain the same term in multiple fields than documents that
  42. contain this term in only the best of those multiple fields, without confusing
  43. this with the better case of two different terms in the multiple fields.
  44. If a document matches multiple clauses, the `dis_max` query calculates the
  45. relevance score for the document as follows:
  46. . Take the relevance score from a matching clause with the highest score.
  47. . Multiply the score from any other matching clauses by the `tie_breaker` value.
  48. . Add the highest score to the multiplied scores.
  49. If the `tie_breaker` value is greater than `0.0`, all matching clauses count,
  50. but the clause with the highest score counts most.
  51. --