普通聚合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"//聚合對象 } } } } } }