### 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 (obj instanceof String) {
            return BytesRefs.toBytesRef(obj);
        } else if (obj instanceof CharBuffer) {
            return new BytesRef((CharBuffer) obj);
        } else if (obj instanceof BigInteger) {
            return BytesRefs.toBytesRef(obj);
        }
        return obj;
    }
    /**
     * This helper method checks if the object passed in is a {@link BytesRef} or {@link CharBuffer},
     * if so it converts it to a utf8 string.
     * @param obj the input object
     * @return the same input object or a utf8 string if input was of type {@link BytesRef} or {@link CharBuffer}
     */
    static Object maybeConvertToString(Object obj) {
        if (obj instanceof BytesRef) {
            return ((BytesRef) obj).utf8ToString();
        } else if (obj instanceof CharBuffer) {
            return new BytesRef((CharBuffer) obj).utf8ToString();
        }
        return obj;
    }
    /**
     * Helper method to convert collection of {@link QueryBuilder} instances to lucene
     * {@link Query} instances. {@link QueryBuilder} that return {@code null} calling
     * their {@link QueryBuilder#toQuery(SearchExecutionContext)} method are not added to the
     * resulting collection.
     */
    static Collection<Query> toQueries(Collection<QueryBuilder> queryBuilders, SearchExecutionContext context) throws QueryShardException,