Bool Query Usageedit

A query that matches documents matching boolean combinations of other queries. It is built using one or more boolean clauses, each clause with a typed occurrence.

The occurrence types are:

must
The clause (query) must appear in matching documents and will contribute to the score.
filter
The clause (query) must appear in matching documents. However unlike must, the score of the query will be ignored.
should
The clause (query) should appear in the matching document. In a boolean query with no must or filter clauses, one or more should clauses must match a document. The minimum number of should clauses to match can be set using the minimum_should_match parameter.
must_not
The clause (query) must not appear in the matching documents.

Check out the bool queries section for more details on bool queries with NEST.

See the Elasticsearch documentation on bool query for more details.

Fluent DSL exampleedit

q
.Bool(b => b
    .MustNot(m => m.MatchAll())
    .Should(m => m.MatchAll())
    .Must(m => m.MatchAll())
    .Filter(f => f.MatchAll())
    .MinimumShouldMatch(1)
    .Boost(2))

Object Initializer syntax exampleedit

new BoolQuery
{
    MustNot = new QueryContainer[] { new MatchAllQuery() },
    Should = new QueryContainer[] { new MatchAllQuery() },
    Must = new QueryContainer[] { new MatchAllQuery() },
    Filter = new QueryContainer[] { new MatchAllQuery() },
    MinimumShouldMatch = 1,
    Boost = 2
}

Example json output. 

{
  "bool": {
    "must": [
      {
        "match_all": {}
      }
    ],
    "must_not": [
      {
        "match_all": {}
      }
    ],
    "should": [
      {
        "match_all": {}
      }
    ],
    "filter": [
      {
        "match_all": {}
      }
    ],
    "minimum_should_match": 1,
    "boost": 2.0
  }
}