doc-exports/docs/css/umn/en-us_topic_0000001528659125.html
Zheng, Xiu 2dfeaff8f9 css umn 23.5.1 20240520
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Zheng, Xiu <zhengxiu@huawei.com>
Co-committed-by: Zheng, Xiu <zhengxiu@huawei.com>
2024-06-06 16:15:58 +00:00

2.3 KiB

Grouping and Aggregation of Low-cardinality Fields

Low-cardinality fields have high data clustering performance when being sorted, which facilitates vectorized optimization. Assume that the following query statement exists:

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"
              }
            }
          }
        }
      }
    }
  }
}

Assume that the region and host are low-cardinality fields. To use the enhanced aggregation, set the parameters as follows:

The clustering key must be a prefix subset of the sorting key.

// Configure an index
"settings" : {
    "index" : {
        "search" : {
            "turbo" : {
                "enabled" : "true" // Enable optimization
            }
        },
        "sort" : { // Specify a sorting key
            "field" : [
                "region",
                "host",
                "other"
            ]
        },
        "cluster" : {
            "field" : [ // Specify a clustering key
                "region",
                "host"
            ]
        }
    }
}