Skip to content

Commit 5d08083

Browse files
committed
A tad of aggregation documentation
1 parent 1bf2fb7 commit 5d08083

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
var descriptor = new SearchDescriptor<MySearchType>().Query(q => q.MatchAll());
24+
25+
descriptor.Aggregations(aggr =>
26+
{
27+
foreach (var term in MyFilters)
28+
{
29+
aggr.Filter(term.Name, filter => filter
30+
.Filter(f => f
31+
.Term("TheTermField", term.Term)))
32+
}
33+
34+
return aggr;
35+
});
36+
37+
var result = client.Search<MySearchType>(descriptor);
38+
39+
And then you can access the aggregation results as normal.

0 commit comments

Comments
 (0)