c# - NEST Elasticsearch : how to return certain fields along with aggregated results?

标签 c# elasticsearch nest elasticsearch-net

聚合后,我需要查询某些字段。

文档结构是:

{
  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/

相关文章:

elasticsearch - 数组上的术语聚合

c# - 删除 .net core 2.0 中的 cookie

c# - 使用批处理文件从命令行调用 C# exe

go - 使用 Go olivere/elastic 进行 Elasticsearch 查询以过滤 value1 == value2 的文档

ruby-on-rails - 这种搜索称为什么类型,什么是最好的搜索方式?

c# - 在NEST中创建IndexName的实例

c# - 如何订阅 TFS 上的工作项状态更改?

java - 网络/代理身份验证(WebClient.UseDefaultCredentials 替代方案)

python - 使用elasticsearch的jupyter python笔记本

c# - C# Elasticsearch 与嵌套的精确文本匹配