bool-query.asciidoc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. The `bool` query takes a _more-matches-is-better_ approach, so the score from
  25. each matching `must` or `should` clause will be added together to provide the
  26. final `_score` for each document.
  27. [source,js]
  28. --------------------------------------------------
  29. {
  30. "bool" : {
  31. "must" : {
  32. "term" : { "user" : "kimchy" }
  33. },
  34. "must_not" : {
  35. "range" : {
  36. "age" : { "from" : 10, "to" : 20 }
  37. }
  38. },
  39. "should" : [
  40. {
  41. "term" : { "tag" : "wow" }
  42. },
  43. {
  44. "term" : { "tag" : "elasticsearch" }
  45. }
  46. ],
  47. "minimum_should_match" : 1,
  48. "boost" : 1.0
  49. }
  50. }
  51. --------------------------------------------------