Skip to content

array_index_out_of_bounds_exception when elastic search request is huge in size #140495

@monica-m1992

Description

@monica-m1992

Elasticsearch Version

8.17.2

Installed Plugins

No response

Java Version

bundled

OS Version

N/A

Problem Description

Getting the following exception when search query is very huge

{
    "error": {
        "root_cause": [],
        "type": "search_phase_execution_exception",
        "reason": "",
        "phase": "fetch",
        "grouped": true,
        "failed_shards": [],
        "caused_by": {
            "type": "array_index_out_of_bounds_exception",
            "reason": "Index 242 out of bounds for length 242"
        }
    },
    "status": 500
}

Steps to Reproduce

{
    "query": {
        "bool": {
            "filter": [
                {
                    "bool": {
                        "must": [
                            {
                                "bool": {
                                    "filter": [
                                        {
                                            "bool": {
                                                "must_not": [
                                                    {
                                                        "terms": {
                                                            "xxx: [
                                                                "YYY"
                                                            ]
                                                        }
                                                    }
                                                ]
                                            }
                                        }
                                    ]
                                }
                            }
                        ],
                        "must_not": [
                            {
                                "match": {
                                    "xxx": {
                                        "query": "YYY"
                                    }
                                }
                            }
                        ],
                        "should": [
                            {
                                "match": {
                                    "xxx": {
                                        "query": "ZZZ"
                                    }
                                }
                            }
                        ]
                    }
                }
            ],
            "must": [
                {
                    "bool": {
                        "must": [
                            {
                                "query_string": {
                                    "fields": [
                                        "AAA^1.2999999523162842",
                                .... <around 90 fields>
                                    ],
                                    "lenient": true,
                                    "query": "\"AAA\" || \"BBB\" || <599 string seperated by || operator> "
                                }
                            },
                            {
                                "bool": {
                                    "minimum_should_match": "1",
                                    "should": [
                                        {
                                            "match": {
                                                "XXX": {
                                                    "query": "YYYY"
                                                }
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                }
            ]
        }
    },
    "explain": false,
    "_source": {
        "excludes": [],
        "includes": [
           "XXX",
            <115 fields>
        ]
    },
    "highlight": {
        "fields": {
            "XXX": {},
            <91 fields>
        }
    },
    "timeout": "60s",
    "track_total_hits": true,
    "track_scores": true,
    "size": 10000
} 

Logs (if relevant)

In ES getting this exception

{"@timestamp":"2025-12-04T09:41:09.304Z", "log.level": "WARN", "message":"TransportMultiSearchAction failure", "ecs.version": "1.2.0","service.name":"ES_ECS","event.dataset":"elasticsearch.server","process.thread.name":"elasticsearch[mdm-es-master-zone-b-0][search][T#7]","log.logger":"org.elasticsearch.action.search.TransportMultiSearchAction","elasticsearch.cluster.uuid":"bbfB3EfVQZ6osom5oHf3qA","elasticsearch.node.id":"j4NQDwkdRr-QKGG-IJA6TQ","elasticsearch.node.name":"mdm-es-master-zone-b-0","elasticsearch.cluster.name":"mdm","error.type":"org.elasticsearch.action.search.SearchPhaseExecutionException","error.message":"","error.stack_trace":"Failed to execute phase [fetch], \n\tat [org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:693)\n\tat](mailto:org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:693)\n\tat) [org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.FetchSearchPhase$1.onFailure(FetchSearchPhase.java:101)\n\tat](mailto:org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.FetchSearchPhase$1.onFailure(FetchSearchPhase.java:101)\n\tat) [org.elasticsearch.server@8.17.2/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:29)\n\tat](mailto:org.elasticsearch.server@8.17.2/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:29)\n\tat) [org.elasticsearch.server@8.17.2/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:34)\n\tat](mailto:org.elasticsearch.server@8.17.2/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:34)\n\tat) [org.elasticsearch.server@8.17.2/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:1023)\n\tat](mailto:org.elasticsearch.server@8.17.2/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:1023)\n\tat) [org.elasticsearch.server@8.17.2/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:27)\n\tat](mailto:org.elasticsearch.server@8.17.2/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:27)\n\tat) java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)\n\tat java.base/java.lang.Thread.run(Thread.java:1575)\nCaused by: java.lang.ArrayIndexOutOfBoundsException: Index 217 out of bounds for length 217\n\tat [org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.SearchPhaseController.getHits(SearchPhaseController.java:463)\n\tat](mailto:org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.SearchPhaseController.getHits(SearchPhaseController.java:463)\n\tat) [org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.SearchPhaseController.merge(SearchPhaseController.java:376)\n\tat](mailto:org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.SearchPhaseController.merge(SearchPhaseController.java:376)\n\tat) [org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.FetchSearchPhase.moveToNextPhase(FetchSearchPhase.java:248)\n\tat](mailto:org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.FetchSearchPhase.moveToNextPhase(FetchSearchPhase.java:248)\n\tat) [org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.FetchSearchPhase.innerRun(FetchSearchPhase.java:117)\n\tat](mailto:org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.FetchSearchPhase.innerRun(FetchSearchPhase.java:117)\n\tat) [org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.FetchSearchPhase$1.doRun(FetchSearchPhase.java:96)\n\tat](mailto:org.elasticsearch.server@8.17.2/org.elasticsearch.action.search.FetchSearchPhase$1.doRun(FetchSearchPhase.java:96)\n\tat) [org.elasticsearch.server@8.17.2/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:27)\n\t](mailto:org.elasticsearch.server@8.17.2/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:27)\n\t)... 6 more\n"}

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions