question:

How can I do multiple nested aggregation?

I have tried something like this:

Aggregations(x => x
.Nested("Facets", y => y.Path("categories")
.Aggregations(r => r.Terms("categories", w => w.Field(q => q.Categories.FirstOrDefault().Id))
)).Nested("Facets2", s => s.Path("brand")
.Aggregations(e => e.Terms("brand", w => w.Field(q => q.Brand.Id))
)));

But it returns Facets2 as a child of Facets

Can anyone help?

Answer:

The aggregations that you have work as expected with NEST client version 1.7.1 as demonstrated with this example

void Main()
{
var settings = new ConnectionSettings();
var connection = new InMemoryConnection(settings);
var client = new ElasticClient(connection : connection); var response = client.Search<Example>(s => s
.Aggregations(aggs => aggs
.Nested("Facets", nested => nested
.Path(p => p.Categories)
.Aggregations(r => r
.Terms("categories", w => w
.Field(q => q.Categories.FirstOrDefault().Id)
)
)
)
.Nested("Facets2", nested => nested
.Path(p => p.Brand)
.Aggregations(e => e
.Terms("brand", w => w
.Field(q => q.Brand.Id)
)
)
)
)
); Console.WriteLine(Encoding.UTF8.GetString(response.RequestInformation.Request));
} public class Example
{
public IList<Category> Categories { get; set; }
public Brand Brand { get; set; }
} public class Brand
{
public int Id { get; set; }
} public class Category
{
public int Id { get; set; }
}

This outputs the following request query

{
"aggs": {
"Facets": {
"nested": {
"path": "categories"
},
"aggs": {
"categories": {
"terms": {
"field": "categories.id"
}
}
}
},
"Facets2": {
"nested": {
"path": "brand"
},
"aggs": {
"brand": {
"terms": {
"field": "brand.id"
}
}
}
}
}
}

 

NEST - How can i do multiple nested aggregation?的更多相关文章

  1. [Angular 2] Select From Multiple Nested Angular 2 Elements

    You have complete control over the elements you nest inside of your component instance by using sele ...

  2. TN035: Using Multiple Resource Files and Header Files with Visual C++

    TN035: Using Multiple Resource Files and Header Files with Visual C++ This note describes how the Vi ...

  3. aggregation 详解3(bucket aggregation)

    概述 桶分聚合不进行权值的计算,他们对文档根据聚合请求中提供的判断条件(比如:{"from":0,  "to":100})来进行分组(桶分). 桶分聚合还会额外 ...

  4. Elasticsearch: nested对象

    在处理大量数据时,关系数据库存在很多问题. 无论是速度,高效处理,有效并行化,可扩展性还是成本,当数据量开始增长时,关系数据库都会失败.该关系数据库的另一个挑战是必须预先定义关系和模式.Elastic ...

  5. Elastic search中使用nested类型的内嵌对象

    在大数据的应用环境中,往往使用反范式设计来提高读写性能. 假设我们有个类似简书的系统,系统里有文章,用户也可以对文章进行赞赏.在关系型数据库中,如果按照数据库范式设计,需要两张表:一张文章表和一张赞赏 ...

  6. Struts1 标签库 说明

    Struts提供了五个标签库,即:HTML.Bean.Logic.Template和Nested. HTML标签 : 用来创建能够和Struts 框架和其他相应的HTML 标签交互的HTML 输入表单 ...

  7. 10 Go 1.10 Release Notes

    Go 1.10 Release Notes Introduction to Go 1.10 Changes to the language Ports Tools Default GOROOT &am ...

  8. Struts1标签

    Struts1 标签库  说明 Struts提供了五个标签库,即:HTML.Bean.Logic.Template和Nested. HTML 标签 : 用来创建能够和Struts 框架和其他相应的HT ...

  9. angular语法:Controller As

    这个东东我觉得很好哟. 数据可以在同一个页面的不同的controller之间自由穿梭... 当然, https://thinkster.io/a-better-way-to-learn-angular ...

随机推荐

  1. 实例: Java代码操作oracle数据库(JDBC+sevrlet+jsp+html)

    1, 注册页面 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.or ...

  2. 关于html与body的高度问题

    转自https://blog.csdn.net/javaloveiphone/article/details/51098972 一.html,body{height:100%} 今天看到一个CSS样式 ...

  3. 微信H5支付常见问题汇总

    常见问题 一.回调页面 正常流程用户支付完成后会返回至发起支付的页面,如需返回至指定页面,则可以在MWEB_URL后拼接上redirect_url参数,来指定回调页面. 如,您希望用户支付完成后跳转至 ...

  4. 洛谷 P2899 [USACO08JAN]手机网络Cell Phone Network(树形动规)

    题目描述 Farmer John has decided to give each of his cows a cell phone in hopes to encourage their socia ...

  5. 分布式理论系列(一)从 ACID 到 CAP 到 BASE

    分布式理论系列(一)从 ACID 到 CAP 到 BASE 一.ACID 1.1 事务的四个特征: (1) Atomic(原子性) 事务必须是一个原子的操作序列单元,事务中包含的各项操作在一次执行过程 ...

  6. mongo find

    MongoVUE 对应成语句,结构如下: db.logs.find({ "message" : /消息/ }, { "message" : 1 }).limit ...

  7. git fatal:HttpRequestException encountered

    网上查了一下发现是Github 禁用了TLS v1.0 and v1.1,必须更新Windows的git凭证管理器,才行. https://github.com/Microsoft/Git-Crede ...

  8. OpengGL中图形绘制先后问题

    OpengGL中图形绘制先后问题 在opengl中,场景绘制总有个先后的顺序,也有个程序先后的问题,图形程序在前在后,对最终的图形的影响如何? (1)设置图中的点(蓝色)与线条(浅蓝)z分量都是0,如 ...

  9. 如何注册GitHub

    一.个人介绍 姓名:张志龙 学号:1413042026 班级:网工141 爱好:宅物 能力:c++编程 二.注册 注册GitHub其实很简单 首先我们要做的是打开官网 www.github.com(如 ...

  10. vue+elementui后台管理快捷代码片段

    Form <el-form labelPosition="right" labelWidth="10%" size="small" : ...