WARNING: Version 5.x has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Filter Aggregation Usageedit
Defines a single bucket of all the documents in the current document set context that match a specified filter. Often this will be used to narrow down the current aggregation context to a specific set of documents.
Be sure to read the Elasticsearch documentation on Filter Aggregation
Fluent DSL exampleedit
s => s .Aggregations(aggs => aggs .Filter("bethels_projects", date => date .Filter(q => q.Term(p => p.LeadDeveloper.FirstName, FirstNameToFind)) .Aggregations(childAggs => childAggs .Terms("project_tags", avg => avg.Field(p => p.CuratedTags.First().Name)) ) ) )
Object Initializer syntax exampleedit
new SearchRequest<Project> { Aggregations = new FilterAggregation("bethels_projects") { Filter = new TermQuery {Field = Field<Project>(p => p.LeadDeveloper.FirstName), Value = FirstNameToFind}, Aggregations = new TermsAggregation("project_tags") {Field = Field<Project>(p => p.CuratedTags.First().Name)} } }
Example json output.
{ "aggs": { "bethels_projects": { "filter": { "term": { "leadDeveloper.firstName": { "value": "pierce" } } }, "aggs": { "project_tags": { "terms": { "field": "curatedTags.name" } } } } } }