dis-max-query.asciidoc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. [[query-dsl-dis-max-query]]
  2. === Dis Max Query
  3. A query that generates the union of documents produced by its
  4. subqueries, and that scores each document with the maximum score for
  5. that document as produced by any subquery, plus a tie breaking increment
  6. for any additional matching subqueries.
  7. This is useful when searching for a word in multiple fields with
  8. different boost factors (so that the fields cannot be combined
  9. equivalently into a single search field). We want the primary score to
  10. be the one associated with the highest boost, not the sum of the field
  11. scores (as Boolean Query would give). If the query is "albino elephant"
  12. this ensures that "albino" matching one field and "elephant" matching
  13. another gets a higher score than "albino" matching both fields. To get
  14. this result, use both Boolean Query and DisjunctionMax Query: for each
  15. term a DisjunctionMaxQuery searches for it in each field, while the set
  16. of these DisjunctionMaxQuery's is combined into a BooleanQuery.
  17. The tie breaker capability allows results that include the same term in
  18. multiple fields to be judged better than results that include this term
  19. in only the best of those multiple fields, without confusing this with
  20. the better case of two different terms in the multiple fields.The
  21. default `tie_breaker` is `0.0`.
  22. This query maps to Lucene `DisjunctionMaxQuery`.
  23. [source,js]
  24. --------------------------------------------------
  25. GET /_search
  26. {
  27. "query": {
  28. "dis_max" : {
  29. "tie_breaker" : 0.7,
  30. "boost" : 1.2,
  31. "queries" : [
  32. {
  33. "term" : { "age" : 34 }
  34. },
  35. {
  36. "term" : { "age" : 35 }
  37. }
  38. ]
  39. }
  40. }
  41. }
  42. --------------------------------------------------
  43. // CONSOLE