Skip to content

[BUG] OpenSearch 3.x — date_histogram + sub-terms aggregation throws array_index_out_of_bounds_exception #22342

Description

@adenchua

Describe the bug

Summary

After upgrading OpenSearch from 2.19 to 3.7, a date_histogram aggregation with a
terms sub-aggregation began failing with:

search_phase_execution_exception
  caused_by: array_index_out_of_bounds_exception
  reason: "Index 31 out of bounds for length 31"

The plain date_histogram worked; the error only appeared once the terms
sub-aggregation was added.

The index was created when OpenSearch version was 2.11

Managed to fix it by disabling the filter rewrite optimization in cluster settings ("search.max_aggregation_rewrite_filters": 0), but was wondering if this is a system bug in the first place waiting to be patched.

Related component

Search:Aggregations

To Reproduce

An aggregation query with around 50K documents spanning from 1970 to 2025. (A few records dated 1970, and the rest in the recent years 2020-2024) Created a date_histogram aggregation query with calendar_interval set to month/year, and a sub terms aggregation with an array of strings. (filtered to documents LTE 2024, matching around 8K records)

Expected behavior

The buckets to show up like it did previously prior to the upgrade

Additional Details

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions