### Elasticsearch Version

8.9.0

### Installed Plugins

_No response_

### Java Version

_bundled_

### OS Version

Ubuntu 23.04

### Problem Description

Trying to use KNN on dense vectors I obtain an index out of bounds exception on the second run of my reproducer script (originally, I was trying to figure out why I don't get matches even when querying knn with the exact vector contained).

FIRST RUN:

```
Creating index with dense vector field
======================================
{"acknowledged":true,"shards_acknowledged":true,"index":"test_faces"}

Sending some docs
=================
{"took":53,"errors":false,"items":[{"index":{"_index":"test_faces","_id":"3c9effc1037d48bda70e2a7347facccc_1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1,"status":201}},{"index":{"_index":"test_faces","_id":"03c0dbc7e1d8477d8a489951e54921cb_1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":1,"_primary_term":1,"status":201}},{"index":{"_index":"test_faces","_id":"9ce12fd38e6f4af4b1e3427554fd7d85_1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":2,"_primary_term":1,"status":201}},{"index":{"_index":"test_faces","_id":"9ee553d50f9341a2a763f1bc100e22f0_0","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":3,"_primary_term":1,"status":201}},{"index":{"_index":"test_faces","_id":"db29de5fc97540cab49674f7a1ea8141_0","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":4,"_primary_term":1,"status":201}},{"index":{"_index":"test_faces","_id":"7ede3783e4be4d7f824da548b95c2409_3","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":5,"_primary_term":1,"status":201}},{"index":{"_index":"test_faces","_id":"9b9cd80011ee4d1ea786309f419d2907_0","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":6,"_primary_term":1,"status":201}},{"index":{"_index":"test_faces","_id":"fc6da18f2a1748d69c45bd726adae5ff_0","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":7,"_primary_term":1,"status":201}},{"index":{"_index":"test_faces","_id":"cfc26e33a7764113a036b0556f60f8b5_0","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":8,"_primary_term":1,"status":201}},{"index":{"_index":"test_faces","_id":"97840f576236421c8694c3e71cd6edc7_0","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":9,"_primary_term":1,"status":201}}]}

Sending KNN query using vector of first doc
===========================================
{"took":0,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":0,"relation":"eq"},"max_score":null,"hits":[]}}
```



SECOND RUN:

```
Creating index with dense vector field
======================================
{"error":{"root_cause":[{"type":"resource_already_exists_exception","reason":"index [test_faces/PfzJRX73SRWDRq6mQrrYfQ] already exists","index_uuid":"PfzJRX73SRWDRq6mQrrYfQ","index":"test_faces"}],"type":"resource_already_exists_exception","reason":"index [test_faces/PfzJRX73SRWDRq6mQrrYfQ] already exists","index_uuid":"PfzJRX73SRWDRq6mQrrYfQ","index":"test_faces"},"status":400}

Sending some docs
=================
{"took":20,"errors":false,"items":[{"index":{"_index":"test_faces","_id":"3c9effc1037d48bda70e2a7347facccc_1","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":10,"_primary_term":1,"status":200}},{"index":{"_index":"test_faces","_id":"03c0dbc7e1d8477d8a489951e54921cb_1","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":11,"_primary_term":1,"status":200}},{"index":{"_index":"test_faces","_id":"9ce12fd38e6f4af4b1e3427554fd7d85_1","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":12,"_primary_term":1,"status":200}},{"index":{"_index":"test_faces","_id":"9ee553d50f9341a2a763f1bc100e22f0_0","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":13,"_primary_term":1,"status":200}},{"index":{"_index":"test_faces","_id":"db29de5fc97540cab49674f7a1ea8141_0","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":14,"_primary_term":1,"status":200}},{"index":{"_index":"test_faces","_id":"7ede3783e4be4d7f824da548b95c2409_3","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":15,"_primary_term":1,"status":200}},{"index":{"_index":"test_faces","_id":"9b9cd80011ee4d1ea786309f419d2907_0","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":16,"_primary_term":1,"status":200}},{"index":{"_index":"test_faces","_id":"fc6da18f2a1748d69c45bd726adae5ff_0","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":17,"_primary_term":1,"status":200}},{"index":{"_index":"test_faces","_id":"cfc26e33a7764113a036b0556f60f8b5_0","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":18,"_primary_term":1,"status":200}},{"index":{"_index":"test_faces","_id":"97840f576236421c8694c3e71cd6edc7_0","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":19,"_primary_term":1,"status":200}}]}

Sending KNN query using vector of first doc
===========================================
{"error":{"root_cause":[{"type":"index_out_of_bounds_exception","reason":"Index 2147483647 out of bounds for length 10"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"fetch","grouped":true,"failed_shards":[{"shard":0,"index":"test_faces","node":"waoxWY4iQYKJqsKyhMc49A","reason":{"type":"index_out_of_bounds_exception","reason":"Index 2147483647 out of bounds for length 10"}}],"caused_by":{"type":"index_out_of_bounds_exception","reason":"Index 2147483647 out of bounds for length 10","caused_by":{"type":"index_out_of_bounds_exception","reason":"Index 2147483647 out of bounds for length 10"}}},"status":500}benjamin@poincare:benjamin@poincare:~/git/open-media-server/backend/src/test/scripts$ 
```



### Steps to Reproduce

Please see :[ https://gitlab.com/bhabegger/open-media-server/-/blob/d5889285c6d9062889e765c65a02f734dcfcc33c/backend/src/test/scripts/no_knn_results.sh
]( https://gitlab.com/bhabegger/open-media-server/-/blob/d5889285c6d9062889e765c65a02f734dcfcc33c/backend/src/test/scripts/no_knn_results.sh
)
Run script twice in a row (second run will fail creating the already existing index, but that's ok)


### Logs (if relevant)

_No response_
server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapperTests.java
private static final IndexVersion INDEXED_BY_DEFAULT_PREVIOUS_INDEX_VERSION = IndexVersion.V_8_10_0;
    private final ElementType elementType;
    private final boolean indexed;
    private final boolean indexOptionsSet;
    public DenseVectorFieldMapperTests() {
        this.elementType = randomFrom(ElementType.BYTE, ElementType.FLOAT);
        this.indexed = randomBoolean();
        this.indexOptionsSet = this.indexed && randomBoolean();
    }
    @Override
    protected void minimalMapping(XContentBuilder b) throws IOException {
        indexMapping(b, true);
    }
    @Override
    protected void minimalMapping(XContentBuilder b, IndexVersion indexVersion) throws IOException {
        indexMapping(b, indexVersion.onOrAfter(DenseVectorFieldMapper.INDEXED_BY_DEFAULT_INDEX_VERSION));
    }
    private void indexMapping(XContentBuilder b, boolean indexedByDefault) throws IOException {
        b.field("type", "dense_vector").field("dims", 4);
        if (elementType != ElementType.FLOAT) {
            b.field("element_type", elementType.toString());
        }
        if (indexedByDefault || indexed) {
            
            b.field("index", indexed);
        }
        if (indexed) {
            b.field("similarity", "dot_product");
            if (indexOptionsSet) {