File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
docs/contents/nest/aggregations Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ template : layout.jade
3+ title : Aggregations
4+ menusection : aggregations
5+ menuitem : advanced
6+ ---
7+
8+ # Advanced usage
9+
10+ ## Creating multiple aggregations from an IEnumerable
11+
12+ Premise:
13+ You have an IEnumerable<TestObject > MyFilters, and you want to build a Filter aggregation with a Term filter for each of the TestObjects you have.
14+
15+ class TestObject
16+ {
17+ public string Name { get; set; }
18+ public string Term { get; set; }
19+ }
20+
21+ Then you could do something like this:
22+
23+ IEnumerable<TestObject> MyFilters;
24+
25+ var descriptor = new SearchDescriptor<MySearchType>().Query(q => q.MatchAll());
26+
27+ descriptor.Aggregations(aggr =>
28+ {
29+ foreach (var term in MyFilters)
30+ {
31+ aggr.Filter(term.Name, filter => filter
32+ .Filter(f => f
33+ .Term("TheTermField", term.Term)))
34+ }
35+
36+ return aggr;
37+ });
38+
39+ var result = client.Search<MySearchType>(descriptor);
40+
41+ And then you can access the aggregation results as normal.
You can’t perform that action at this time.
0 commit comments