### Elasticsearch Version

8.8

### Installed Plugins

_No response_

### Java Version

_bundled_

### OS Version

all

### Problem Description

`_terms_enum` queries against a `keyword` field build automata out of their prefix string, to be intersected with the terms dictionary on the relevant field.  We don't have a limit on the size of this prefix, meaning that if somebody (either accidentally or maliciously) passes a very large string here, we can run out of memory.

### Steps to Reproduce

Send a very large string as part of a `_terms_enum` request against a keyword field.

### Logs (if relevant)

_No response_
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/termsenum/TermsEnumRequestTests.java
request.indexFilter(QueryBuilders.termQuery("field", randomAlphaOfLength(5)));
        }
        String[] randomIndices = new String[randomIntBetween(1, 5)];
        for (int i = 0; i < randomIndices.length; i++) {
            randomIndices[i] = randomAlphaOfLengthBetween(5, 10);
        }
        request.indices(randomIndices);
        if (randomBoolean()) {
            request.indicesOptions(randomBoolean() ? IndicesOptions.strictExpand() : IndicesOptions.lenientExpandOpen());
        }
        return request;
    }
    @Override
    protected TermsEnumRequest createXContextTestInstance(XContentType xContentType) {
        return createTestInstance()
            
            .indices("test")
            .indicesOptions(TermsEnumRequest.DEFAULT_INDICES_OPTIONS);
    }
    @Override
    protected NamedWriteableRegistry getNamedWriteableRegistry() {
        return namedWriteableRegistry;
    }
    @Override
    protected NamedXContentRegistry xContentRegistry() {
        return xContentRegistry;
    }
    @Override
    protected Writeable.Reader<TermsEnumRequest> instanceReader() {
        return TermsEnumRequest::new;