### 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
* While it extracts inner hits, child inner hits are inlined into the inner hit builder they belong to.
     */
    protected void extractInnerHitBuilders(Map<String, InnerHitContextBuilder> innerHits) {}
    /**
     * Parses and returns a query (excluding the query field that wraps it). To be called by API that support
     * user provided queries. Note that the returned query may hold inner queries, and so on. Calling this method
     * will initialize the tracking of nested depth to make sure that there's a limit to the number of queries
     * that can be nested within one another (see {@link org.elasticsearch.search.SearchModule#INDICES_MAX_NESTED_DEPTH_SETTING}.
     * This variant of the method does not support collecting statistics about queries usage.
     */
    public static QueryBuilder parseTopLevelQuery(XContentParser parser) throws IOException {
        return parseTopLevelQuery(parser, queryName -> {});
    }
    /**
     * Parses and returns a query (excluding the query field that wraps it). To be called by API that support
     * user provided queries. Note that the returned query may hold inner queries, and so on. Calling this method
     * will initialize the tracking of nested depth to make sure that there's a limit to the number of queries
     * that can be nested within one another (see {@link org.elasticsearch.search.SearchModule#INDICES_MAX_NESTED_DEPTH_SETTING}.
     * The method accepts a string consumer that will be provided with each query type used in the parsed content, to be used
     * for instance to collect statistics about queries usage.
     */
    public static QueryBuilder parseTopLevelQuery(XContentParser parser, Consumer<String> queryNameConsumer) throws IOException {
        FilterXContentParser parserWrapper = new FilterXContentParserWrapper(parser) {
            int nestedDepth;
            @Override
            public <T> T namedObject(Class<T> categoryClass, String name, Object context) throws IOException {
                if (categoryClass.equals(QueryBuilder.class)) {
                    nestedDepth++;
                    if (nestedDepth > maxNestedDepth) {
                        throw new IllegalArgumentException(