### 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
}
    @Override
    protected TermsEnumRequest doParseInstance(XContentParser parser) throws IOException {
        return TermsEnumAction.fromXContent(parser, "test");
    }
    @Override
    protected TermsEnumRequest mutateInstance(TermsEnumRequest instance) throws IOException {
        List<Consumer<TermsEnumRequest>> mutators = new ArrayList<>();
        mutators.add(request -> { request.field(randomValueOtherThan(request.field(), () -> randomAlphaOfLengthBetween(3, 10))); });
        mutators.add(request -> {
            String[] indices = ArrayUtils.concat(instance.indices(), generateRandomStringArray(5, 10, false, false));
            request.indices(indices);
        });
        mutators.add(request -> {
            IndicesOptions indicesOptions = randomValueOtherThan(
                request.indicesOptions(),
                () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean())
            );
            request.indicesOptions(indicesOptions);
        });
        mutators.add(
            request -> request.indexFilter(request.indexFilter() != null ? request.indexFilter().boost(2) : QueryBuilders.matchAllQuery())
        );
        TermsEnumRequest mutatedInstance = copyInstance(instance);
        Consumer<TermsEnumRequest> mutator = randomFrom(mutators);
        mutator.accept(mutatedInstance);
        return mutatedInstance;
    }
}