### Description

There is a hard limit on the size of terms that can be indexed in lucene.  However, we don't check this at query time, which can lead to memory issues if the term query in question is case insensitive.  Very long terms are normally a sign of user error, so we should check up-front the length of the input and throw and exception if it is greater than `IndexWriter.MAX_TERM_LENGTH`.
server/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java
if (queryName() != null && rewritten.queryName() == null) { 
            rewritten.queryName(queryName());
        }
        if (boost() != DEFAULT_BOOST && rewritten.boost() == DEFAULT_BOOST) {
            rewritten.boost(boost());
        }
        return rewritten;
    }
    protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws IOException {
        
        
        if (queryRewriteContext == null) {
            return this;
        }
        final CoordinatorRewriteContext crc = queryRewriteContext.convertToCoordinatorRewriteContext();
        if (crc != null) {
            return doCoordinatorRewrite(crc);
        }
        final SearchExecutionContext sec = queryRewriteContext.convertToSearchExecutionContext();
        if (sec != null) {
            return doSearchRewrite(sec);
        }
        final QueryRewriteContext context = queryRewriteContext.convertToIndexMetadataContext();
        if (context != null) {
            return doIndexMetadataRewrite(context);
        }
        return this;
    }
    /**
     * @param coordinatorRewriteContext A {@link QueryRewriteContext} that enables limited rewrite capabilities