class CrossFieldsQueryBuilder extends QueryBuilder {
        private FieldAndFieldType[] blendedFields;

        CrossFieldsQueryBuilder(float tiebreaker) {
            super(tiebreaker);
        }

        @Override
        public List<Query> buildGroupedQueries(MultiMatchQueryType type, Map<String, Float> fieldNames, Object value, String minimumShouldMatch) {
            Map<Analyzer, List<FieldAndFieldType>> groups = new HashMap<>();
            List<Query> queries = new ArrayList<>();
            for (Map.Entry<String, Float> entry : fieldNames.entrySet()) {
                String name = entry.getKey();
                MappedFieldType fieldType = context.fieldMapper(name);
                if (fieldType != null) {
                    Analyzer actualAnalyzer = getAnalyzer(fieldType, type == MultiMatchQueryType.PHRASE);
                    name = fieldType.name();
                    if (!groups.containsKey(actualAnalyzer)) {
                        groups.put(actualAnalyzer, new ArrayList<>());
                    }
                    Float boost = entry.getValue();
                    boost = boost == null ? Float.valueOf(1.0f) : boost;
                    groups.get(actualAnalyzer).add(new FieldAndFieldType(fieldType, boost));
                } else {
                    queries.add(new MatchNoDocsQuery("unknown field " + name));
                }
            }
            for (List<FieldAndFieldType> group : groups.values()) {
                if (group.size() > 1) {
                    blendedFields = new FieldAndFieldType[group.size()];
                    int i = 0;
                    for (FieldAndFieldType fieldAndFieldType : group) {
                        blendedFields[i++] = fieldAndFieldType;
                    }
                } else {
                    blendedFields = null;
                }
                /*
                 * We have to pick some field to pass through the superclass so
                 * we just pick the first field. It shouldn't matter because
                 * fields are already grouped by their analyzers/types.
                 */
                String representativeField = group.get(0).fieldType.name();
                Query q = parseGroup(type.matchQueryType(), representativeField, 1f, value, minimumShouldMatch);
                if (q != null) {
                    queries.add(q);
                }
            }

            return queries.isEmpty() ? null : queries;
        }

        @Override
        public Query blendTerms(Term[] terms, MappedFieldType fieldType) {
            if (blendedFields == null || blendedFields.length == 1) {
                return super.blendTerms(terms, fieldType);
            }
            BytesRef[] values = new BytesRef[terms.length];
            for (int i = 0; i < terms.length; i++) {
                values[i] = terms[i].bytes();
            }
            return MultiMatchQuery.blendTerms(context, values, commonTermsCutoff, tieBreaker, blendedFields);
        }

        @Override
        public Query blendTerm(Term term, MappedFieldType fieldType) {
            if (blendedFields == null) {
                return super.blendTerm(term, fieldType);
            }
            return MultiMatchQuery.blendTerm(context, term.bytes(), commonTermsCutoff, tieBreaker, blendedFields);
        }

        @Override
        public Query termQuery(MappedFieldType fieldType, BytesRef value) {
            /*
             * Use the string value of the term because we're reusing the
             * portion of the query is usually after the analyzer has run on
             * each term. We just skip that analyzer phase.
             */
            return blendTerm(new Term(fieldType.name(), value.utf8ToString()), fieldType);
        }

        @Override
        public Query blendPhrase(PhraseQuery query, MappedFieldType type) {
            if (blendedFields == null) {
                return super.blendPhrase(query, type);
            }
            /**
             * We build phrase queries for multi-word synonyms when {@link QueryBuilder#autoGenerateSynonymsPhraseQuery} is true.
             */
            return MultiMatchQuery.blendPhrase(query, tieBreaker, blendedFields);
        }
    }

    static Query blendTerm(QueryShardContext context, BytesRef value, Float commonTermsCutoff, float tieBreaker,
                           FieldAndFieldType... blendedFields) {
        return blendTerms(context, new BytesRef[] {value}, commonTermsCutoff, tieBreaker, blendedFields);
    }

    static Query blendTerms(QueryShardContext context, BytesRef[] values, Float commonTermsCutoff, float tieBreaker,
                            FieldAndFieldType... blendedFields) {<FILL_FUNCTION_BODY>

        List<Query> queries = new ArrayList<>();
        Term[] terms = new Term[blendedFields.length * values.length];
        float[] blendedBoost = new float[blendedFields.length * values.length];
        int i = 0;
        for (FieldAndFieldType ft : blendedFields) {
            for (BytesRef term : values) {
                Query query;
                try {
                    query = new TermQuery(new Term(ft.fieldType.name(), term));
                } catch (IllegalArgumentException e) {
                    // the query expects a certain class of values such as numbers
                    // of ip addresses and the value can't be parsed, so ignore this
                    // field
                    continue;
                } catch (ElasticsearchParseException parseException) {
                    // date fields throw an ElasticsearchParseException with the
                    // underlying IAE as the cause, ignore this field if that is
                    // the case
                    if (parseException.getCause() instanceof IllegalArgumentException) {
                        continue;
                    }
                    throw parseException;
                }
                float boost = ft.boost;
                while (query instanceof BoostQuery) {
                    BoostQuery bq = (BoostQuery) query;
                    query = bq.getQuery();
                    boost *= bq.getBoost();
                }
                if (query.getClass() == TermQuery.class) {
                    terms[i] = ((TermQuery) query).getTerm();
                    blendedBoost[i] = boost;
                    i++;
                } else {
                    if (boost != 1f && query instanceof MatchNoDocsQuery == false) {
                        query = new BoostQuery(query, boost);
                    }
                    queries.add(query);
                }
            }
        }
        if (i > 0) {
            terms = Arrays.copyOf(terms, i);
            blendedBoost = Arrays.copyOf(blendedBoost, i);
            if (commonTermsCutoff != null) {
                queries.add(BlendedTermQuery.commonTermsBlendedQuery(terms, blendedBoost, commonTermsCutoff));
            } else {
                queries.add(BlendedTermQuery.dismaxBlendedQuery(terms, blendedBoost, tieBreaker));
            }
        }
        if (queries.size() == 1) {
            return queries.get(0);
        } else {
            // best effort: add clauses that are not term queries so that they have an opportunity to match
            // however their score contribution will be different
            // TODO: can we improve this?
            return new DisjunctionMaxQuery(queries, 1.0f);
        }
    
<methods>public void <init>(org.elasticsearch.index.query.QueryShardContext) ,public Query parse(org.elasticsearch.index.search.MatchQuery.Type, java.lang.String, java.lang.Object) ,public void setAnalyzer(java.lang.String) ,public void setAnalyzer(Analyzer) ,public void setAutoGenerateSynonymsPhraseQuery(boolean) ,public void setCommonTermsCutoff(java.lang.Float) ,public void setEnablePositionIncrements(boolean) ,public void setFuzziness(org.elasticsearch.common.unit.Fuzziness) ,public void setFuzzyPrefixLength(int) ,public void setFuzzyRewriteMethod(MultiTermQuery.RewriteMethod) ,public void setLenient(boolean) ,public void setMaxExpansions(int) ,public void setOccur(BooleanClause.Occur) ,public void setPhraseSlop(int) ,public void setTranspositions(boolean) ,public void setZeroTermsQuery(org.elasticsearch.index.search.MatchQuery.ZeroTermsQuery) <variables>static final float DEFAULT_BOOST,public static final boolean DEFAULT_LENIENCY,public static final int DEFAULT_PHRASE_SLOP,public static final org.elasticsearch.index.search.MatchQuery.ZeroTermsQuery DEFAULT_ZERO_TERMS_QUERY,private static final org.elasticsearch.common.logging.DeprecationLogger DEPRECATION_LOGGER,protected Analyzer analyzer,protected boolean autoGenerateSynonymsPhraseQuery,protected java.lang.Float commonTermsCutoff,protected final non-sealed org.elasticsearch.index.query.QueryShardContext context,protected boolean enablePositionIncrements,protected org.elasticsearch.common.unit.Fuzziness fuzziness,protected int fuzzyPrefixLength,protected MultiTermQuery.RewriteMethod fuzzyRewriteMethod,protected boolean lenient,protected int maxExpansions,protected BooleanClause.Occur occur,protected int phraseSlop,protected boolean transpositions,protected org.elasticsearch.index.search.MatchQuery.ZeroTermsQuery zeroTermsQuery