doc-exports/docs/css/umn/en-us_topic_0000001528499145.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

1.9 KiB

High-cardinality Field Histogram Aggregation

High-cardinality fields are usually used for histogram grouping and aggregation instead of single-point grouping and aggregation. For example, collecting the statistics of logs at a certain period. Assume that the following query statement exists:

POST testindex/_search?pretty
{
  "size": 0,
  "aggs": {
    "avg_score": {
      "avg": {
        "field": "score"
      },
      "aggs": {
        "groupbytime": {
          "date_histogram": {
            "field": "timestamp",
            "calendar_interval": "day"
          }
        }
      }
    }
  }
}

This query groups the field timestamp using a histogram and calculates the average score. timestamp is a typical high-cardinality field. To use the enhanced aggregation for the preceding query, set parameters as follows:

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