普通聚合html
POST /product/_search { "size": 0, "aggs": { "agg_city": { "terms": { "field": "departureCitys" //字段 } } } }
父子结构的索引的聚合elasticsearch
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"//聚合对象 } } } } } }