elasticsearch nested aggregation
创建测试Mapping
PUT /products
{
"mappings": {
"properties": {
"resellers": {
"type": "nested",
"properties": {
"reseller": {
"type": "keyword"
},
"price": {
"type": "double"
}
}
}
}
}
}
插入测试数据
PUT /products/_doc/0
{
"name": "LED TV",
"resellers": [
{
"reseller": "companyA",
"price": 350
},
{
"reseller": "companyB",
"price": 500
}
]
}
测试aggs查询
GET /products/_search?size=0
{
"query": {
"match": {
"name": "led tv"
}
},
"aggs": {
"resellers": {
"nested": {
"path": "resellers"
},
"aggs": {
"min_price": {
"min": {
"field": "resellers.price"
}
}
}
}
}
}
统计结果解析
{
...
"aggregations":

本文介绍了如何在Elasticsearch中使用nested aggregation进行数据统计,通过创建测试Mapping、插入数据和执行aggs查询,得出符合条件的文档总数为2,最低价格为350.0。并提供了相关Java客户端实现及官方文档链接。
最低0.47元/天 解锁文章
1102

被折叠的 条评论
为什么被折叠?



