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?
Nested aggregationeditA special single bucket aggregation that enables aggregating nested documents. For example, lets say we have an index of products, and each product holds the list of resellers - each having its own price for the product.
Elasticsearch Aggregations provide you with the ability to group and perform calculations and statistics (such as sums and averages) on your data by using a simple search query. An aggregation can be viewed as a working unit that builds analytical information across a set of documents.
Elasticsearch organizes aggregations into three categories: Metric aggregations that calculate metrics, such as a sum or average, from field values. Bucket aggregations that group documents into buckets, also called bins, based on field values, ranges, or other criteria.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With