您当前的位置: 首页 >  搜索

Dongguo丶

暂无认证

  • 1浏览

    0关注

    472博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

41深入聚合数据分析_搜索+聚合:统计指定品牌下每个颜色的销量

Dongguo丶 发布时间:2021-11-26 07:04:00 ,浏览量:1

实际上来说,我们之前学习的搜索相关的知识,完全可以和聚合组合起来使用

对于sql分组,既有搜索又有分组

select count(*)
from tvs.sales
where brand like "%长%"
group by price

es aggregation有一个概念scope:任何的聚合,都必须在搜索出来的结果数据中进行,搜索结果,就是聚合分析操作的scope

搜索品牌是小米的电视,并根据颜色分组

GET /tvs/sales/_search 
{
  "size": 0,
  "query": {
    "term": {
      "brand": {
        "value": "小米"
      }
    }
  },
  "aggs": {
    "group_by_color": {
      "terms": {
        "field": "color"
      }
    }
  }
}

响应结果

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "group_by_color": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "绿色",
          "doc_count": 1
        },
        {
          "key": "蓝色",
          "doc_count": 1
        }
      ]
    }
  }
}
关注
打赏
1638062488
查看更多评论
立即登录/注册

微信扫码登录

0.0392s