I'm quite new to elasticsearch and I have yet to find a question specifically about this. If it is already answered, I apologize in advanced and I hope you can point me to the correct direction.
I was looking for a way to implement the following in NEST:
"aggs" : {
"fieldA" : {
"terms" : {
"field" : "fieldA"
}
},
"fieldB" : {
"terms" : {
"field" : "fieldB"
}
}
}
I have tried this:
.Aggregations(q => q.Terms("fieldA", r => r.Field(s => s.fieldA)) && q.Terms("fieldB", r => r.Field(s => s.fieldB)))
and this:
.Aggregations(q => q.Terms("fieldA", r => r.Field(s => s.fieldA)))
.Aggregations(q => q.Terms("fieldB", r => r.Field(s => s.fieldB)))
Which both failed to work. Am I missing something else?
You can specify multiple aggregations like so:
.Aggregations(a => a
.Terms("fieldA", t => t.Field(s => s.FieldA))
.Terms("fieldB", t => t.Field(s => s.FieldB))
)
Each aggregation descriptor, internally, adds itself to a dictionary (using the agg name as a key) and then returns itself so you can continually add more.
Apologies for the lack of documentation around aggs in NEST. We are in the process of revamping the docs and we'll be sure to include an example of the above use case.