Skip to content

Commit b83ac02

Browse files
committed
Merge pull request #942 from andersosthus/documentation
AggregationContainer documentation
2 parents 1bf2fb7 + 02dd82d commit b83ac02

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.

0 commit comments

Comments
 (0)