Skip to content

[BUG] array_index_out_of_bounds_exception with wildcard/regexp and aggregationsΒ #20838

@mvo-zyres

Description

@mvo-zyres

Describe the bug

When searching with wildcard/regexp query and value aggregations the search returns one of these three exceptions:

  • array_index_out_of_bounds_exception (most of the time)
  • index_out_of_bounds_exception
  • e_o_f_exception

When removing either wildcard/regex query or value aggregations, then the search works.
This happens in OpenSearch 3.4.0 and 3.5.0. In version 3.3.2 it still worked.

Related component

Search:Aggregations

To Reproduce

  1. run OpenSearch 3.4.0 or 3.5.0

  2. create an index

PUT test-index
{
  "mappings": {
    "properties": {
      "dimensions": {
        "type": "wildcard"
      },
      "brand": {
        "type": "keyword"
      },
      "display_allow": {
        "type": "boolean"
      }
    }
  }
}
  1. generate documents
const axios = require("axios")

function random(list) {
  return list[Math.floor(Math.random() * list.length)]
}

function randomDimensions() {
  const s = random(["w", "s", "a"]);
  const w = random([195, 205, 215, 225, 235, 245, 255]);
  const r = random([45, 50, 55, 60]);
  const d = random([16, 17, 18, 19]);
  return `${s}${w}${r}${d}`
}

function randomBrand() {
  return random(["audi", "mercedes", "bmw", "volkswagen", "porsche", "opel", "smart"]);
}

function randomDisplayAllow() {
  return random([true, false])
}

async function run() {
  for (let i = 0; i < 2000; i++) {
    await axios.post("http://localhost:9200/test-index/_doc", {
      dimensions: randomDimensions(),
      brand: randomBrand(),
      display_allow: randomDisplayAllow(),
    })
  }
}

run()
  1. run the search query
POST test-index/_search
{
    "query": {
        "bool": {
            "must": [
                {
                    "regexp": {
                        "dimensions": {
                            "value": ".*255.*55.*"
                        }
                    }
                }
            ],
            "filter": [
              {
                "term": {
                  "display_allow": true
                }
              }
            ]
        }
    },
    "aggs": {
        "brand": {
            "filter": {
                "bool": {
                    "filter": [
                        {
                            "term": {
                                "display_allow": true
                            }
                        }
                    ]
                }
            },
            "aggs": {
                "_values": {
                    "terms": {
                        "field": "brand",
                        "size": 100
                    }
                }
            }
        }
    }
}
  1. see error response
{
  "error": {
    "root_cause": [
      {
        "type": "array_index_out_of_bounds_exception",
        "reason": "arraycopy: source index -1831 out of bounds for byte[240]"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "test-index",
        "node": "7ofbA85ETOS3rIUn0IG38Q",
        "reason": {
          "type": "array_index_out_of_bounds_exception",
          "reason": "arraycopy: source index -1831 out of bounds for byte[240]",
          "suppressed": [
            {
              "type": "array_index_out_of_bounds_exception",
              "reason": "arraycopy: source index -1831 out of bounds for byte[240]"
            },
            {
              "type": "array_index_out_of_bounds_exception",
              "reason": "arraycopy: source index -14072 out of bounds for byte[240]"
            },
            {
              "type": "array_index_out_of_bounds_exception",
              "reason": "arraycopy: source index -14072 out of bounds for byte[240]"
            }
          ]
        }
      }
    ],
    "caused_by": {
      "type": "array_index_out_of_bounds_exception",
      "reason": "arraycopy: source index -1831 out of bounds for byte[240]",
      "caused_by": {
        "type": "array_index_out_of_bounds_exception",
        "reason": "arraycopy: source index -1831 out of bounds for byte[240]",
        "suppressed": [
          {
            "type": "array_index_out_of_bounds_exception",
            "reason": "arraycopy: source index -1831 out of bounds for byte[240]"
          },
          {
            "type": "array_index_out_of_bounds_exception",
            "reason": "arraycopy: source index -14072 out of bounds for byte[240]"
          },
          {
            "type": "array_index_out_of_bounds_exception",
            "reason": "arraycopy: source index -14072 out of bounds for byte[240]"
          }
        ]
      }
    }
  },
  "status": 500
}

Expected behavior

It should not return an error, but rather correctly return the documents and the aggregations.

Additional Details

Plugins

  • opensearch-security

Host/Environment versions

  • Docker: 29.2.1
  • OpenSearch: 3.4.0 / 3.5.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    πŸ†• New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions