### 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
*                                  happening on the coordinator node before execution moves to the data node.
     * @return A {@link QueryBuilder} representing the rewritten query which could be executed without going to
     * the date node.
     */
    protected QueryBuilder doCoordinatorRewrite(final CoordinatorRewriteContext coordinatorRewriteContext) {
        return this;
    }
    /**
     * @param searchExecutionContext A {@link QueryRewriteContext} that enables full rewrite capabilities
     *                               happening on the data node with all information available for rewriting.
     * @return A {@link QueryBuilder} representing the rewritten query.
     */
    protected QueryBuilder doSearchRewrite(final SearchExecutionContext searchExecutionContext) throws IOException {
        return doIndexMetadataRewrite(searchExecutionContext);
    }
    /**
     * Optional rewrite logic that only needs access to index level metadata and services (e.g. index settings and mappings)
     * on the data node, but not the shard / Lucene index.
     * The can_match phase can use this logic to early terminate a search without doing any search related i/o.
     *
     * @param context an {@link QueryRewriteContext} instance that has access the mappings and other index metadata
     * @return A {@link QueryBuilder} representing the rewritten query, that could be used to determine whether this query yields result.
     */
    protected QueryBuilder doIndexMetadataRewrite(final QueryRewriteContext context) throws IOException {
        return this;
    }
    /**
     * For internal usage only!
     *
     * Extracts the inner hits from the query tree.