bool-query.asciidoc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. [[query-dsl-bool-query]]
  2. === Bool Query
  3. A query that matches documents matching boolean combinations of other
  4. queries. The bool query maps to Lucene `BooleanQuery`. It is built using
  5. one or more boolean clauses, each clause with a typed occurrence. The
  6. occurrence types are:
  7. [cols="<,<",options="header",]
  8. |=======================================================================
  9. |Occur |Description
  10. |`must` |The clause (query) must appear in matching documents.
  11. |`should` |The clause (query) should appear in the matching document. In
  12. a boolean query with no `must` clauses, one or more `should` clauses
  13. must match a document. The minimum number of should clauses to match can
  14. be set using the
  15. <<query-dsl-minimum-should-match,`minimum_should_match`>>
  16. parameter.
  17. |`must_not` |The clause (query) must not appear in the matching
  18. documents.
  19. |=======================================================================
  20. The bool query also supports `disable_coord` parameter (defaults to
  21. `false`). Basically the coord similarity computes a score factor based
  22. on the fraction of all query terms that a document contains. See Lucene
  23. `BooleanQuery` for more details.
  24. [source,js]
  25. --------------------------------------------------
  26. {
  27. "bool" : {
  28. "must" : {
  29. "term" : { "user" : "kimchy" }
  30. },
  31. "must_not" : {
  32. "range" : {
  33. "age" : { "from" : 10, "to" : 20 }
  34. }
  35. },
  36. "should" : [
  37. {
  38. "term" : { "tag" : "wow" }
  39. },
  40. {
  41. "term" : { "tag" : "elasticsearch" }
  42. }
  43. ],
  44. "minimum_should_match" : 1,
  45. "boost" : 1.0
  46. }
  47. }
  48. --------------------------------------------------