### 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
timeout(clone.timeout());
        setParentTask(clone.getParentTask());
    }
    public TermsEnumRequest(StreamInput in) throws IOException {
        super(in);
        field = in.readString();
        string = in.readOptionalString();
        searchAfter = in.readOptionalString();
        caseInsensitive = in.readBoolean();
        size = in.readVInt();
        indexFilter = in.readOptionalNamedWriteable(QueryBuilder.class);
    }
    @Override
    public void writeTo(StreamOutput out) throws IOException {
        super.writeTo(out);
        out.writeString(field);
        out.writeOptionalString(string);
        out.writeOptionalString(searchAfter);
        out.writeBoolean(caseInsensitive);
        out.writeVInt(size);
        out.writeOptionalNamedWriteable(indexFilter);
    }
    @Override
    public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
        builder.startObject();
        builder.field("field", field);
        if (string != null) {
            builder.field("string", string);
        }
        if (searchAfter != null) {