61_elasticSearch 对每个用户发表的博客进行分组

61_对每个用户发表的博客进行分组

更多干货

1、构造更多测试数据

PUT /website/users/3
{
  "name": "虚竹",
  "email": "caoren@sina.com",
  "birthday": "1970-10-24"
}

PUT /website/blogs/3
{
  "title": "我是虚竹",
  "content": "我是虚竹啊,各位同学们!",
  "userInfo": {
    "userId": 1,
    "userName": "虚竹"
  }
}

PUT /website/users/2
{
  "name": "超人",
  "email": "caoren@sina.com",
  "birthday": "1980-02-02"
}

PUT /website/blogs/4
{
  "title": "超人的身世揭秘",
  "content": "大家好,我是超人,所以我的身世是。",
  "userInfo": {
    "userId": 2,
    "userName": "超人"
  }
}

2、对每个用户发表的博客进行分组

比如说,小鱼儿发表的那些博客,超人发表了哪些博客,虚竹发表了哪些博客

GET /website/blogs/_search 
{
  "size": 0, 
  "aggs": {
    "group_by_username": {
      "terms": {
        "field": "userInfo.username.keyword"
      },
      "aggs": {
        "top_blogs": {
          "top_hits": {
            "_source": {
              "include": "title"
            }, 
            "size": 5
          }
        }
      }
    }
  }
}

相关文章


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值