Filtered Query Usage

edit

The filtered query is used to combine a query which will be used for scoring with another query which will only be used for filtering the result set.

Deprecated in 2.0.0-beta1. Use the bool query instead with a must clause for the query and a filter clause for the filter.

See the Elasticsearch documentation on filtered query for more details.

Fluent DSL example

edit
q
.Filtered(c => c
    .Name("named_query")
    .Boost(1.1)
    .Filter(qq => qq.MatchAll(m => m.Name("filter")))
    .Query(qq => qq.MatchAll(m => m.Name("query")))
)

Object Initializer syntax example

edit
new FilteredQuery()
{
    Name = "named_query",
    Boost = 1.1,
    Filter = new MatchAllQuery { Name ="filter" },
    Query = new MatchAllQuery() { Name = "query" },
}

Example json output.

{
  "filtered": {
    "_name": "named_query",
    "boost": 1.1,
    "filter": {
      "match_all": {
        "_name": "filter"
      }
    },
    "query": {
      "match_all": {
        "_name": "query"
      }
    }
  }
}