Reputation: 1307
I need to query certain fields, after aggregating.
Document structure is:
{
id: 1,
type: AA,
hashValue: "qweqeqwdwwew"
...and many more fields
}
I want to aggregate by 'hashValue', so that i get only unique hashValues and the return results should also have the type. I need help with NEST query.
The current query to aggregate is:
var result = esClient.Search < EType > (q => q
.Index(esClient.Index)
.Routing(id.ToString(CultureInfo.InvariantCulture))
.Aggregations(ag => ag
.Terms("Hash", ee => ee
.Field(f => f.hashValue)))));
How can i extend it return type field along with hashValue?
Thanks.
Upvotes: 2
Views: 839
Reputation: 6357
From your comments, it seems like you want to aggregate documents per type per hash value. For that the Nest query you need is as under:
var result = esClient.Search<EType>(q => q
.Index(esClient.Index)
.Routing(id.ToString(CultureInfo.InvariantCulture)
.Aggregations(agHash => agHash
.Terms("Hash", eeHash => eeHash
.Field(fHash => fHash.hashValue)
.Aggregations(agType => agType
.Terms("Types", eeType => eeType
.Field(fType => fType.typeValue))))));
Upvotes: 1