43.过滤+聚合:统计价格大于1200的电视平均价格

主要知识点:

  • 搜索+聚合
  • 过滤+聚合

需求是:找出所有价格大于1200元的电视,然后对之些电视求平均价格

语法:

GET /tvs/sales/_search

{

"size": 0,

"query": {

"constant_score": {"filter": {"range": {"price": {"gte": 1200}}}}

},

"aggs": {"avg_price": {"avg": {"field": "price"}}}

}

   

执行结果是:

{

"took": 13,

"timed_out": false,

"_shards": {

"total": 5,

"successful": 5,

"failed": 0

},

"hits": {

"total": 7,

"max_score": 0,

"hits": []

},

"aggregations": {

"avg_price": {

"value": 2885.714285714286

}

}

}

   

posted @ 2018-03-09 20:22  outback123  阅读(133)  评论(0编辑  收藏  举报