NEST - How can i do multiple nested aggregation?
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?的更多相关文章
- [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 ...
- 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 ...
- aggregation 详解3(bucket aggregation)
概述 桶分聚合不进行权值的计算,他们对文档根据聚合请求中提供的判断条件(比如:{"from":0, "to":100})来进行分组(桶分). 桶分聚合还会额外 ...
- Elasticsearch: nested对象
在处理大量数据时,关系数据库存在很多问题. 无论是速度,高效处理,有效并行化,可扩展性还是成本,当数据量开始增长时,关系数据库都会失败.该关系数据库的另一个挑战是必须预先定义关系和模式.Elastic ...
- Elastic search中使用nested类型的内嵌对象
在大数据的应用环境中,往往使用反范式设计来提高读写性能. 假设我们有个类似简书的系统,系统里有文章,用户也可以对文章进行赞赏.在关系型数据库中,如果按照数据库范式设计,需要两张表:一张文章表和一张赞赏 ...
- Struts1 标签库 说明
Struts提供了五个标签库,即:HTML.Bean.Logic.Template和Nested. HTML标签 : 用来创建能够和Struts 框架和其他相应的HTML 标签交互的HTML 输入表单 ...
- 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 ...
- Struts1标签
Struts1 标签库 说明 Struts提供了五个标签库,即:HTML.Bean.Logic.Template和Nested. HTML 标签 : 用来创建能够和Struts 框架和其他相应的HT ...
- angular语法:Controller As
这个东东我觉得很好哟. 数据可以在同一个页面的不同的controller之间自由穿梭... 当然, https://thinkster.io/a-better-way-to-learn-angular ...
随机推荐
- Linux 入侵检测
一.检查系统日志 检查系统错误登陆日志,统计IP重试次数 # 这里使用了lastb命令,该命令需要root权限,可以显示所有登陆信息.这里仅仅显示的root用户的,读者可以更具实际情况自行确定,或者直 ...
- QByteArray to QString
QByteArray => QString void BarEngine::ByteArrayToString(QByteArray &ba, QString &str) { i ...
- Jdeveloper下Svn的使用
Jdeveloper下Svn的使用 官方pdf:jdeveloper使用svn 官方网地址:http://www.oracle.com/technetwork/cn/java/subversion-0 ...
- code1001 舒适的路线
n次最小生成树kruskal 将所有的边排序,权值小的在前. 设排序后第i条边为路径中的最长边,那么这条路径一定是由1~i中的一些边组成 因为最高速和最低速的差尽量小,最高速确定了,最低速应尽量大. ...
- MyBatis 实用篇(二)配置文件
MyBatis 实用篇(二)配置文件 一.全局配置 全局配置:http://www.mybatis.org/mybatis-3/zh/configuration.html <?xml versi ...
- 查找mysql的my.cnf位置
1. which mysqld /user/local/mysql/bin/mysqld --verbose --help |grep -A 1 'Default options'
- The left-hand side of an assignment must be a variable,代码中使用了中文的字符
进行ajax测试,报这个错误,代码检测无误,然后就是查了相关文档 发现是符号错误,eclipse识别中文符号,就会报这个错误,而且eclipse的js里需要写冒号结尾,附个代码. <body&g ...
- Oracle学习笔记(九)
十二.PL/SQL 1.PL/SQL程序的结构和组成 示例:给员工涨工资(根据职位涨工资) 总裁涨1000 经理涨800 其他员工涨400 学习原因:1.操作数据库效率最高 2.为了后期的存储过程的学 ...
- 从Objective-C到Swift,你必须会的(一)#pragma mark
在Objective-C里,为了让代码组织的有序也方便用control+6的快捷键在Xcode中查找,所以出现了一个大家都很熟悉的东东.这就是:#prama mark. #pragma mark 但 ...
- HDU1863 畅通工程 2017-04-12 19:25 59人阅读 评论(0) 收藏
畅通工程 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissi ...