### 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
builder.field("search_after", searchAfter);
        }
        builder.field("size", size);
        builder.field("timeout", timeout());
        builder.field("case_insensitive", caseInsensitive);
        if (indexFilter != null) {
            builder.field("index_filter", indexFilter);
        }
        return builder.endObject();
    }
    @Override
    public ActionRequestValidationException validate() {
        ActionRequestValidationException validationException = super.validate();
        if (field == null) {
            validationException = ValidateActions.addValidationError("field cannot be null", validationException);
        }
        if (timeout() == null) {
            validationException = ValidateActions.addValidationError("Timeout cannot be null", validationException);
        } else {
            if (timeout().getSeconds() > 60) {
                validationException = ValidateActions.addValidationError("Timeout cannot be > 1 minute", validationException);
            }
        }
        return validationException;
    }
    @Override
    public boolean allowsRemoteIndices() {
        return true;
    }
    /**