1.第一个分析需求:计算每个tag下的商品数量
GET /ecommerce/product/_search
{
"aggs": {
"group_by_tags": {
"terms": {
"field": "tags"
}
}
}
}
-----------------------------------------------------------------------
{
"took": 48,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "ecommerce",
"_type": "product",
"_id": "2",
"_score": 1,
"_source": {
"name": "jiajieshi yagao",
"desc": "youxiao fangzhu",
"price": 25,
"producer": "jiajieshi producer",
"tags": [
"fangzhu"
]
}
},
{
"_index": "ecommerce",
"_type": "product",
"_id": "4",
"_score": 1,
"_source": {
"name": "heiren",
"desc": "xiren yagao",
"price": 50,
"producer": "jiajieshi yagao",
"tags": [
"heiren"
]
}
},
{
"_index": "ecommerce",
"_type": "product",
"_id": "1",
"_score": 1,
"_source": {
"name": "heiren",
"desc": "xiren yagao",
"price": 50,
"producer": "jiajieshi yagao",
"tags": [
"heiren"
]
}
},
{
"_index": "ecommerce",
"_type": "product",
"_id": "3",
"_score":