### 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/main/java/org/elasticsearch/xpack/core/termsenum/action/TermsEnumRequest.java
* The field to look inside for values
     */
    public TermsEnumRequest field(String field) {
        this.field = field;
        return this;
    }
    /**
     * Indicates if detailed information about query is requested
     */
    public String field() {
        return field;
    }
    /**
     * The string required in matching field values
     */
    public TermsEnumRequest string(String string) {
        this.string = string;
        return this;
    }
    /**
     * The string required in matching field values
     */
    @Nullable
    public String string() {
        return string;
    }
    /**
     * The string after which to find matching field values (enables pagination of previous request)
     */
    @Nullable