Elasticsearch专题精讲—— Aggregations —— Bucket aggregations(桶聚合)

Aggregations —— Bucket aggregations(桶聚合)

https://www.elastic.co/guide/en/elasticsearch/reference/8.8/search-aggregations-bucket.html#search-aggregations-bucket

Bucket aggregations don’t calculate metrics over fields like the metrics aggregations do, but instead, they create buckets of documents. Each bucket is associated with a criterion (depending on the aggregation type) which determines whether or not a document in the current context "falls" into it. In other words, the buckets effectively define document sets. In addition to the buckets themselves, the bucket aggregations also compute and return the number of documents that "fell into" each bucket.

桶聚合不像度量聚合那样在字段上计算指标,而是创建文档桶。每个桶都和一个标准相关(取决于聚合类型),这个标准决定了当前上下文中的文档是否会“归入”该桶。换言之,桶有效地定义了文档集合。除了桶本身之外,桶聚合还会计算并返回每个桶中文档的数量。

我理解意思是说: 桶聚合是一种在 Elasticsearch 中对文档进行分类的方法。与度量聚合不同,桶聚合不会在字段上计算指标,而是会创建文档的各种桶。每个桶都与一个特定的条件相关联,具体取决于聚合类型,用于判断在当前上下文中的文档是否满足该条件并“归入”相应的桶。简而言之,桶有效地将满足特定条件的文档分组到一个集合中。

例如,假设您有一组商品数据,其中包含每个商品的类别和价格。您可以使用“terms”桶聚合按商品类别对数据进行分组。对于价格区间,您可以使用“range”桶聚合来创建多个价格区间桶,例如 0-100 元、100-200 元等,然后将相应价格范围内的商品归入相应的桶。

除了创建桶之外,桶聚合还可以计算并返回每个桶中文档的数量。例如,在上述商品分类的场景中,桶聚合可以告诉您每个类别中有多少商品,或者在每个价格区间桶中有多少商品。这些信息可帮助您了解数据的分布情况以进行更深入的分析。 总之,桶聚合是一种对 Elasticsearch 中的文档进行分类和分组的方法,它为进一步分析提供了基础。通过使用不同类型的聚合,您可以根据需求创建各种条件的桶,并获得有关每个桶中文档数量的统计信息。

Bucket aggregations, as opposed to metrics aggregations, can hold sub-aggregations. These sub-aggregations will be aggregated for the buckets created by their "parent" bucket aggregation.

与度量聚合不同,桶聚合可以包含子聚合。对于这些子聚合来说,它们会根据其“父级”桶聚合创建的桶进行聚合操作。

There are different bucket aggregators, each with a different "bucketing" strategy. Some define a single bucket, some define fixed number of multiple buckets, and others dynamically create the buckets during the aggregation process.

桶聚合器有很多种,每种都有不同的“分桶”策略。有些聚合器定义一个单一桶,有些定义固定数量的多个桶,还有一些在聚合过程中动态创建桶。

The search.max_buckets cluster setting limits the number of buckets allowed in a single response.

search.max_buckets 集群设置限制了单个响应中允许的桶的数量。

posted @ 2023-06-14 17:30  左扬  阅读(61)  评论(0编辑  收藏  举报
levels of contents