聚合后,我需要查询某些字段。
文档结构是:
{
id: 1,
type: AA,
hashValue: "qweqeqwdwwew"
...and many more fields
}
我想通过“hashValue”进行聚合,以便我只获得唯一的 hashValues 并且返回结果也应该具有该类型。我需要有关 NEST 查询的帮助。
当前要聚合的查询是:
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)))));
我如何扩展它的返回类型字段和 hashValue?
谢谢。
最佳答案
从您的意见来看,您似乎想要按散列值按类型聚合文档。为此,您需要的 Nest 查询如下:
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))))));
关于c# - NEST Elasticsearch : how to return certain fields along with aggregated results?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34261249/