### Elasticsearch Version

8.8.2

### Installed Plugins

_No response_

### Java Version

_bundled_

### OS Version

Mac OS X

### Problem Description

Under certain conditions, fetching a particular field value using the "fields" API can lead to `string_index_out_of_bounds_exception`.
The queried field needs to be inside a "nested" object and in addition to the field name, all fields need to be queries as well (`*`).
Both fields requested also need to be requested with `"include_unmapped": true`. 

### Steps to Reproduce

```
DELETE testindex

PUT testindex
{
    "mappings": {
        "dynamic": "false",
        "properties": {
            "nested_field": {
                "type": "nested",
                "properties": {
                    "file": {
                        "type": "keyword"
                    }
                }
            }
        }
    }
}

POST testindex/_doc
{
    "nested_field": {        
            "file": "somefile.txt"
    }
}

GET testindex/_search
{
  "_source": false,
  "fields": [
    {
      "field": "file",
      "include_unmapped": true
    },
    {
      "field": "*",
      "include_unmapped": true
    }
  ],
  "query": {
    "match_all" : {}
  }
}
```

This gives the following error:
```
{
    "error": {
        [...],
        "caused_by": {
            "type": "string_index_out_of_bounds_exception",
            "reason": "Range [13, 4) out of bounds for length 4",
            "caused_by": {
                "type": "string_index_out_of_bounds_exception",
                "reason": "Range [13, 4) out of bounds for length 4"
            }
        }
    },
    "status": 500
}
```

### Logs (if relevant)

_No response_
server/src/main/java/org/elasticsearch/search/fetch/subphase/FieldFetcher.java
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
 * A helper class to {@link FetchFieldsPhase} that's initialized with a list of field patterns to fetch.
 * Then given a specific document, it can retrieve the corresponding fields through their corresponding {@link ValueFetcher}s.
 */
public class FieldFetcher {
    private record ResolvedField(String field, String matchingPattern, MappedFieldType ft, String format) {}
    /**
     * Build a FieldFetcher for a given search context and collection of fields and formats
     */
    public static FieldFetcher create(SearchExecutionContext context, Collection<FieldAndFormat> fieldAndFormats) {
        List<String> unmappedFetchPattern = new ArrayList<>();
        List<ResolvedField> resolvedFields = new ArrayList<>();
        for (FieldAndFormat fieldAndFormat : fieldAndFormats) {
            String fieldPattern = fieldAndFormat.field;
            String matchingPattern = Regex.isSimpleMatchPattern(fieldPattern) ? fieldPattern : null;
            if (fieldAndFormat.includeUnmapped != null && fieldAndFormat.includeUnmapped) {
                unmappedFetchPattern.add(fieldAndFormat.field);
            }
            for (String field : context.getMatchingFieldNames(fieldPattern)) {
                MappedFieldType ft = context.getFieldType(field);
                
                if (context.isMetadataField(field) && matchingPattern != null) {
                    continue;