elasticsearch 聚合查询

1.查看一天时间内,ip的去重总数

post hqbuy_event_tracking-*/_search
{
  "query":{
    "range": {
      "create_timestamp": {
        "gte": 1702310400,
        "lt": 1702396800
      }
    }
  },
  "size":0,
  "aggs": {
   "group": {
     "cardinality": {
       "field": "ip"
     }
   }
 }
}

 2. 统计sku_goods索引中SpecItems.SpecValue 字段有值的总数,SpecItems属于nested类型

# 统计nested子对象中,SpecValue字段有值的数据总数
POST /sku_goods/_search
{
  "size":0,
  "aggs": {
    "count": {
      "nested": {
        "path": "SpecItems"
      },
      "aggs": {
        "specvalue_count": {
          "value_count": {
            "field": "SpecItems.SpecValue"
          }
        }
      }
    }
  }
}

 3.统计nested子项中,name分组显示名称和数量

POST crawl_element14_sku_info/_search
{
  "size": 0,
  "aggs": {
    "nested_agg": {
      "nested": {
        "path": "SpecInfos"
      },
      "aggs": {
        "group": {
          "terms": {
            "field": "SpecInfos.Name",
            "size": 1000
          }
        }
      }
    }
  }
}

 

posted on 2023-12-13 16:35  花阴偷移  阅读(13)  评论(0编辑  收藏  举报

导航