### Elasticsearch Version

docker.elastic.co/elasticsearch/elasticsearch:8.7.0-eb092238-SNAPSHOT

### Installed Plugins

_No response_

### Java Version

_bundled_

### OS Version

Linux (Docker)

### Problem Description

In some cases, after indexing a document with `_doc_count` into an index with synthetic source, an `array_index_out_of_bounds_exception` exception occurs when searching the index. This seems to be dependent on other documents indexed.

### Steps to Reproduce

Run the following API calls. The docs without `_doc_count` seem to matter; removing just one those stops the exception occurring.

```
DELETE /target

PUT /target
{
  "mappings": {
    "_source": {
      "mode": "synthetic"
    }
  }
}

POST /target/_doc
{
}

POST /target/_doc
{
}

POST /target/_doc
{
}

POST /target/_doc?refresh=true
{
  "_doc_count" : 1
}

GET /target/_search?error_trace
```

### Logs (if relevant)

```
# DELETE /target 200 OK
{
  "acknowledged": true
}
# PUT /target 200 OK
{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "target"
}
# POST /target/_doc 201 Created
{
  "_index": "target",
  "_id": "tlvLjYQBXlvXGQCu14Xw",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 0,
  "_primary_term": 1
}
# POST /target/_doc 201 Created
{
  "_index": "target",
  "_id": "t1vLjYQBXlvXGQCu2IUN",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 1,
  "_primary_term": 1
}
# POST /target/_doc 201 Created
{
  "_index": "target",
  "_id": "uFvLjYQBXlvXGQCu2IUk",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 2,
  "_primary_term": 1
}
# POST /target/_doc?refresh=true 201 Created
{
  "_index": "target",
  "_id": "uVvLjYQBXlvXGQCu2IU2",
  "_version": 1,
  "result": "created",
  "forced_refresh": true,
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 3,
  "_primary_term": 1
}
# GET /target/_search?error_trace 500 Internal Server Error
{
  "error": {
    "root_cause": [
      {
        "type": "array_index_out_of_bounds_exception",
        "reason": "Index 129 out of bounds for length 129",
        "stack_trace": """org.elasticsearch.ElasticsearchException$1: Index 129 out of bounds for length 129
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.ElasticsearchException.guessRootCauses(ElasticsearchException.java:640)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.SearchPhaseExecutionException.guessRootCauses(SearchPhaseExecutionException.java:150)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.ElasticsearchException.guessRootCauses(ElasticsearchException.java:622)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.ElasticsearchException.generateFailureXContent(ElasticsearchException.java:568)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.rest.RestResponse.build(RestResponse.java:175)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.rest.RestResponse.<init>(RestResponse.java:123)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.rest.RestResponse.<init>(RestResponse.java:102)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.rest.action.RestActionListener.onFailure(RestActionListener.java:55)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.rest.action.RestCancellableNodeClient$1.onFailure(RestCancellableNodeClient.java:96)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.client.internal.node.NodeClient$SafelyWrappedActionListener.onFailure(NodeClient.java:170)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.tasks.TaskManager$1.onFailure(TaskManager.java:217)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.support.ContextPreservingActionListener.onFailure(ContextPreservingActionListener.java:38)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionListener$Delegating.onFailure(ActionListener.java:92)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionListener$Delegating.onFailure(ActionListener.java:92)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionListener$RunAfterActionListener.onFailure(ActionListener.java:358)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction.raisePhaseFailure(AbstractSearchAsyncAction.java:751)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:728)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:418)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseDone(AbstractSearchAsyncAction.java:760)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction.onShardFailure(AbstractSearchAsyncAction.java:512)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:349)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionListener$Delegating.onFailure(ActionListener.java:92)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:48)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.SearchTransportService$ConnectionCountingHandler.handleException(SearchTransportService.java:642)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TransportService$UnregisterChildTransportResponseHandler.handleException(TransportService.java:1642)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1372)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1504)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1479)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:50)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.support.ChannelActionListener.onFailure(ChannelActionListener.java:48)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable.onFailure(ActionRunnable.java:92)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:28)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:917)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 129 out of bounds for length 129
	at org.apache.lucene.core@9.4.1/org.apache.lucene.codecs.lucene90.Lucene90PostingsReader$BlockDocsEnum.advance(Lucene90PostingsReader.java:545)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.DocCountFieldMapper$SyntheticFieldLoader.lambda$docValuesLoader$0(DocCountFieldMapper.java:158)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.ObjectMapper$SyntheticSourceFieldLoader$ObjectDocValuesLoader.advanceToDoc(ObjectMapper.java:638)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.SourceLoader$Synthetic$SyntheticLeaf.source(SourceLoader.java:121)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.prepareNonNestedHitContext(FetchPhase.java:242)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.prepareHitContext(FetchPhase.java:190)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase$1.nextDoc(FetchPhase.java:130)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhaseDocsIterator.iterate(FetchPhaseDocsIterator.java:70)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.buildSearchHits(FetchPhase.java:147)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:76)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:672)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:644)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.lambda$executeQueryPhase$2(SearchService.java:495)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:50)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:47)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$3.doRun(ActionRunnable.java:72)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	... 6 more
"""
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "target",
        "node": "eX_04rcZTyWH1U0l5x-PvQ",
        "reason": {
          "type": "array_index_out_of_bounds_exception",
          "reason": "Index 129 out of bounds for length 129",
          "stack_trace": """java.lang.ArrayIndexOutOfBoundsException: Index 129 out of bounds for length 129
	at org.apache.lucene.core@9.4.1/org.apache.lucene.codecs.lucene90.Lucene90PostingsReader$BlockDocsEnum.advance(Lucene90PostingsReader.java:545)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.DocCountFieldMapper$SyntheticFieldLoader.lambda$docValuesLoader$0(DocCountFieldMapper.java:158)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.ObjectMapper$SyntheticSourceFieldLoader$ObjectDocValuesLoader.advanceToDoc(ObjectMapper.java:638)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.SourceLoader$Synthetic$SyntheticLeaf.source(SourceLoader.java:121)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.prepareNonNestedHitContext(FetchPhase.java:242)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.prepareHitContext(FetchPhase.java:190)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase$1.nextDoc(FetchPhase.java:130)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhaseDocsIterator.iterate(FetchPhaseDocsIterator.java:70)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.buildSearchHits(FetchPhase.java:147)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:76)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:672)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:644)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.lambda$executeQueryPhase$2(SearchService.java:495)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:50)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:47)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$3.doRun(ActionRunnable.java:72)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:917)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1589)
"""
        }
      }
    ],
    "caused_by": {
      "type": "array_index_out_of_bounds_exception",
      "reason": "Index 129 out of bounds for length 129",
      "caused_by": {
        "type": "array_index_out_of_bounds_exception",
        "reason": "Index 129 out of bounds for length 129",
        "stack_trace": """java.lang.ArrayIndexOutOfBoundsException: Index 129 out of bounds for length 129
	at org.apache.lucene.core@9.4.1/org.apache.lucene.codecs.lucene90.Lucene90PostingsReader$BlockDocsEnum.advance(Lucene90PostingsReader.java:545)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.DocCountFieldMapper$SyntheticFieldLoader.lambda$docValuesLoader$0(DocCountFieldMapper.java:158)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.ObjectMapper$SyntheticSourceFieldLoader$ObjectDocValuesLoader.advanceToDoc(ObjectMapper.java:638)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.SourceLoader$Synthetic$SyntheticLeaf.source(SourceLoader.java:121)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.prepareNonNestedHitContext(FetchPhase.java:242)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.prepareHitContext(FetchPhase.java:190)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase$1.nextDoc(FetchPhase.java:130)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhaseDocsIterator.iterate(FetchPhaseDocsIterator.java:70)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.buildSearchHits(FetchPhase.java:147)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:76)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:672)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:644)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.lambda$executeQueryPhase$2(SearchService.java:495)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:50)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:47)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$3.doRun(ActionRunnable.java:72)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:917)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1589)
"""
      },
      "stack_trace": """org.elasticsearch.ElasticsearchException$1: Index 129 out of bounds for length 129
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.ElasticsearchException.guessRootCauses(ElasticsearchException.java:640)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:416)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseDone(AbstractSearchAsyncAction.java:760)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction.onShardFailure(AbstractSearchAsyncAction.java:512)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:349)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionListener$Delegating.onFailure(ActionListener.java:92)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:48)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.SearchTransportService$ConnectionCountingHandler.handleException(SearchTransportService.java:642)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TransportService$UnregisterChildTransportResponseHandler.handleException(TransportService.java:1642)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1372)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1504)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1479)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:50)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.support.ChannelActionListener.onFailure(ChannelActionListener.java:48)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable.onFailure(ActionRunnable.java:92)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:28)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:917)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 129 out of bounds for length 129
	at org.apache.lucene.core@9.4.1/org.apache.lucene.codecs.lucene90.Lucene90PostingsReader$BlockDocsEnum.advance(Lucene90PostingsReader.java:545)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.DocCountFieldMapper$SyntheticFieldLoader.lambda$docValuesLoader$0(DocCountFieldMapper.java:158)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.ObjectMapper$SyntheticSourceFieldLoader$ObjectDocValuesLoader.advanceToDoc(ObjectMapper.java:638)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.SourceLoader$Synthetic$SyntheticLeaf.source(SourceLoader.java:121)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.prepareNonNestedHitContext(FetchPhase.java:242)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.prepareHitContext(FetchPhase.java:190)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase$1.nextDoc(FetchPhase.java:130)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhaseDocsIterator.iterate(FetchPhaseDocsIterator.java:70)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.buildSearchHits(FetchPhase.java:147)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:76)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:672)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:644)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.lambda$executeQueryPhase$2(SearchService.java:495)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:50)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:47)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$3.doRun(ActionRunnable.java:72)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	... 6 more
"""
    },
    "stack_trace": """Failed to execute phase [query], all shards failed; shardFailures {[eX_04rcZTyWH1U0l5x-PvQ][target][0]: org.elasticsearch.transport.RemoteTransportException: [6e65998aa961][127.0.0.1:9300][indices:data/read/search[phase/query]]
Caused by: org.elasticsearch.search.fetch.FetchPhaseExecutionException: Fetch Failed [Error running fetch phase for doc [3]]
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhaseDocsIterator.iterate(FetchPhaseDocsIterator.java:73)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.buildSearchHits(FetchPhase.java:147)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:76)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:672)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:644)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.lambda$executeQueryPhase$2(SearchService.java:495)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:50)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:47)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$3.doRun(ActionRunnable.java:72)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:917)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 129 out of bounds for length 129
	at org.apache.lucene.core@9.4.1/org.apache.lucene.codecs.lucene90.Lucene90PostingsReader$BlockDocsEnum.advance(Lucene90PostingsReader.java:545)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.DocCountFieldMapper$SyntheticFieldLoader.lambda$docValuesLoader$0(DocCountFieldMapper.java:158)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.ObjectMapper$SyntheticSourceFieldLoader$ObjectDocValuesLoader.advanceToDoc(ObjectMapper.java:638)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.SourceLoader$Synthetic$SyntheticLeaf.source(SourceLoader.java:121)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.prepareNonNestedHitContext(FetchPhase.java:242)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.prepareHitContext(FetchPhase.java:190)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase$1.nextDoc(FetchPhase.java:130)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhaseDocsIterator.iterate(FetchPhaseDocsIterator.java:70)
	... 15 more
}
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:728)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:418)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseDone(AbstractSearchAsyncAction.java:760)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction.onShardFailure(AbstractSearchAsyncAction.java:512)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:349)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionListener$Delegating.onFailure(ActionListener.java:92)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:48)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.SearchTransportService$ConnectionCountingHandler.handleException(SearchTransportService.java:642)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TransportService$UnregisterChildTransportResponseHandler.handleException(TransportService.java:1642)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1372)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1504)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1479)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:50)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.support.ChannelActionListener.onFailure(ChannelActionListener.java:48)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable.onFailure(ActionRunnable.java:92)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:28)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:917)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: org.elasticsearch.ElasticsearchException$1: Index 129 out of bounds for length 129
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.ElasticsearchException.guessRootCauses(ElasticsearchException.java:640)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:416)
	... 20 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 129 out of bounds for length 129
	at org.apache.lucene.core@9.4.1/org.apache.lucene.codecs.lucene90.Lucene90PostingsReader$BlockDocsEnum.advance(Lucene90PostingsReader.java:545)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.DocCountFieldMapper$SyntheticFieldLoader.lambda$docValuesLoader$0(DocCountFieldMapper.java:158)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.ObjectMapper$SyntheticSourceFieldLoader$ObjectDocValuesLoader.advanceToDoc(ObjectMapper.java:638)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.mapper.SourceLoader$Synthetic$SyntheticLeaf.source(SourceLoader.java:121)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.prepareNonNestedHitContext(FetchPhase.java:242)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.prepareHitContext(FetchPhase.java:190)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase$1.nextDoc(FetchPhase.java:130)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhaseDocsIterator.iterate(FetchPhaseDocsIterator.java:70)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.buildSearchHits(FetchPhase.java:147)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:76)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:672)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:644)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.SearchService.lambda$executeQueryPhase$2(SearchService.java:495)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:50)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:47)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$3.doRun(ActionRunnable.java:72)
	at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	... 6 more
"""
  },
  "status": 500
}
```
server/src/test/java/org/elasticsearch/index/mapper/DocCountFieldMapperTests.java
assertEquals(1, doc.rootDoc().getFields(DOC_COUNT_FIELD).length);
    }
    public void testInvalidDocument_NegativeDocCount() throws Exception {
        DocumentMapper mapper = createDocumentMapper(mapping(b -> {}));
        Exception e = expectThrows(MapperParsingException.class, () -> mapper.parse(source(b -> b.field(CONTENT_TYPE, -100))));
        assertThat(e.getCause().getMessage(), containsString("Field [_doc_count] must be a positive integer"));
    }
    public void testInvalidDocument_ZeroDocCount() throws Exception {
        DocumentMapper mapper = createDocumentMapper(mapping(b -> {}));
        Exception e = expectThrows(MapperParsingException.class, () -> mapper.parse(source(b -> b.field(CONTENT_TYPE, 0))));
        assertThat(e.getCause().getMessage(), containsString("Field [_doc_count] must be a positive integer"));
    }
    public void testInvalidDocument_NonNumericDocCount() throws Exception {
        DocumentMapper mapper = createDocumentMapper(mapping(b -> {}));
        Exception e = expectThrows(MapperParsingException.class, () -> mapper.parse(source(b -> b.field(CONTENT_TYPE, "foo"))));
        assertThat(
            e.getCause().getMessage(),
            containsString("Failed to parse object: expecting token of type [VALUE_NUMBER] but found [VALUE_STRING]")
        );
    }
    public void testInvalidDocument_FractionalDocCount() throws Exception {
        DocumentMapper mapper = createDocumentMapper(mapping(b -> {}));
        Exception e = expectThrows(MapperParsingException.class, () -> mapper.parse(source(b -> b.field(CONTENT_TYPE, 100.23))));
        assertThat(e.getCause().getMessage(), containsString("100.23 cannot be converted to Integer without data loss"));
    }
    public void testInvalidDocument_ArrayDocCount() throws Exception {
        DocumentMapper mapper = createDocumentMapper(mapping(b -> {}));
        Exception e = expectThrows(MapperParsingException.class, () -> mapper.parse(source(b -> b.array(CONTENT_TYPE, 10, 20, 30))));
        assertThat(e.getCause().getMessage(), containsString("Arrays are not allowed for field [_doc_count]."));
    }