ElasticSearch 学习记录之ES几种常见的聚合操作
ElasticSearch 学习记录之ES几种常见的聚合操作
ES几种常见的聚合操作
普通聚合
POST /product/_search
{
"size": 0,
"aggs": {
"agg_city": {
"terms": {
"field": "departureCitys" //字段
}
}
}
}
父子结构的索引的聚合
POST product/_search
{
"size": 0,
"aggs": {
"months": {
"children": {
"type": "price"//子类型
},
"aggs": {
"month": {
"terms": {
"field": "months"
}
}
}
}
}
}
双层嵌套结构索引的聚合查询
POST /product/_search
{
"size": 0,
"aggs": {
"theme": {
"nested": {
"path": "themes"//嵌套对象
},
"aggs": {
"agg_category": {
"terms": {
"field": "themes.category"//聚合对象
},
"aggs": {
"agg_name": {
"nested": {
"path": "themes.items"//嵌套对象的嵌套对象
},
"aggs": {
"agg_name": {
"terms": {
"field": "themes.items.name",//聚合的对象的路径
"size": 10
}
}
}
}
}
}
}
}
}
}
嵌套结构索引的聚合查询
POST /product/_search
{
"size": 0,
"aggs": {
"theme": {
"nested": {
"path": "themes"//嵌套对象
},
"aggs": {
"agg_category": {
"terms": {
"field": "themes.category"//聚合对象
}
}
}
}
}
}