### 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
public String searchAfter() {
        return searchAfter;
    }
    /**
     * The string after which to find matching field values (enables pagination of previous request)
     */
    public TermsEnumRequest searchAfter(String searchAfter) {
        this.searchAfter = searchAfter;
        return this;
    }
    /**
     *  The number of terms to return
     */
    public int size() {
        return size;
    }
    /**
     * The number of terms to return
     */
    public TermsEnumRequest size(int size) {
        this.size = size;
        return this;
    }
    /**
     * If case insensitive matching is required
     */
    public TermsEnumRequest caseInsensitive(boolean caseInsensitive) {
        this.caseInsensitive = caseInsensitive;
        return this;
    }