云搜索服务 CSS-低基字段分组聚合

时间:2024-04-18 15:13:20

低基字段分组聚合

对低基字段,在排序的情况下,具备较好的数据聚簇性,利于向量化优化处理。假如有如下查询语句:

POST testindex/_search
{
  "size": 0,
  "aggs": {
    "groupby_region": {
      "terms": {
        "field": "region"
      },
      "aggs": {
        "groupby_host": {
          "terms": {
            "field": "host"
          },
          "aggs": {
            "avg_cpu_usage": {
              "avg": {
                "field": "cpu_usage"
              }
            }
          }
        }
      }
    }
  }
}

假设region和host为低基字段,如果要使用聚合增强特性,那么设置如下:

聚簇键必须是排序键的前缀子集。

// 索引设置
"settings" : {
    "index" : {
        "search" : {
            "turbo" : {
                "enabled" : "true" // 开启优化
            }
        },
        "sort" : { // 指定排序键
            "field" : [
                "region",
                "host",
                "other"
            ]
        },
        "cluster" : {
            "field" : [ // 指定聚簇键
                "region",
                "host"
            ]
        }
    }
}
support.huaweicloud.com/usermanual-css/css_01_0174.html