Skip to content

[FEATURE] PPL should support terms aggregation with multiple buckets #4208

Closed as duplicate

Description

@noCharger

Is your feature request related to a problem?
Currently, PPL converts multiple field grouping operations into composite aggregations instead of using OpenSearch's native multi_terms aggregation. This leads to:

  1. Inconsistent results between PPL and DSL queries
  2. Suboptimal performance for multi-field grouping

For example, this PPL query:

source = big5
| where `@timestamp` >= '2023-01-05 00:00:00' and `@timestamp` < '2023-01-05 05:00:00'
| stats count() by `process.name`, `cloud.region`
| sort - `count()`

Currently generates this composite aggregation:

{
  "aggregations": {
    "composite_buckets": {
      "composite": {
        "size": 1000,
        "sources": [
          {
            "process.name": {
              "terms": {
                "field": "process.name",
                "missing_bucket": true,
                "missing_order": "first",
                "order": "asc"
              }
            }
          },
          {
            "cloud.region": {
              "terms": {
                "field": "cloud.region",
                "missing_bucket": true,
                "missing_order": "first",
                "order": "asc"
              }
            }
          }
        ]
      },
      "aggregations": {
        "count()": {
          "value_count": {
            "field": "_index"
          }
        }
      }
    }
  }
}

What solution would you like?

Implement optimization to use native multi_terms aggregation when grouping by multiple fields. The above query should generate:

{
  "aggs": {
    "important_terms": {
      "multi_terms": {
        "terms": [
          {
            "field": "process.name"
          },
          {
            "field": "cloud.region"
          }
        ]
      }
    }
  }
}

Activity

  1. added
    enhancement
    on Sep 3, 2025
  2. changed the title [-][FEATURE][/-] [+][FEATURE] PPL should support multi_terms aggregation[/+] on Sep 3, 2025
  3. added
    PPL
    on Sep 3, 2025
  4. LantaoJin commented on Sep 9, 2025

    @LantaoJin
    Member

    It is the followup of #3550

  5. changed the title [-][FEATURE] PPL should support multi_terms aggregation[/-] [+][FEATURE] PPL should support terms aggregation with multiple buckets[/+] on Sep 11, 2025
  6. LantaoJin commented on Sep 11, 2025

    @LantaoJin
    Member

    By deep diving, the multi_terms aggregation cannot sort the results by bucket keys. Instead, it just provides a order by metrics API. So the enhancement seems has to a nested terms aggregation:

    {
      "aggs": {
        "process.name": {
          "terms": {
            "field": "process.name",
            "order": {
              "_key": "asc"
            }
          },
          "aggs": {
            "cloud.region": {
              "terms": {
                "field": "cloud.region",
                "order": {
                  "_key": "asc"
                }
              },
              "aggregations": {
                "count()": {
                  "value_count": {
                    "field": "_index"
                  }
                }
              }
            }
          }
        }
      }
    }
    
  7. LantaoJin commented on Sep 16, 2025

    @LantaoJin
    Member

    List the performance found here #4282 (comment)

  8. LantaoJin commented on Sep 18, 2025

    @LantaoJin
    Member

    Close as duplicated to #4282 , won't do the nested sub-aggregations for multiple buckets.

  9. moved this from Not Started to Done in PPL Trackeron Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

PPLenhancement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions