How to use QueryBuilders class for MultiMatchQuery in Elasticsearch 8.x

Hi everyone, I am a newbie in Elasticseach and am trying out stuff in order to gain more knowledge.
I need help converting the below line of code written in Elasticseach 7.x to 8.x standard.
any pointers to resources that explicitly break it down would be appreciated.

 if (fields.size() > 1) {
            final MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(dto.getSearchTerm())
                    .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)
                    .operator(Operator.AND);

            fields.forEach(queryBuilder::field);

            return queryBuilder;
        }

Try this:

var fields = List.of("field1", "field2");
if (fields.size() > 1) {
  Builder queryBuilder = new MultiMatchQuery.Builder();
  queryBuilder.operator(Operator.And);
  queryBuilder.type(TextQueryType.CrossFields);
  queryBuilder.query("free text");
  queryBuilder.fields(fields);
}

Thanks @RabBit_BR . can you please point me to a relevant resource where I get the v7 implementation transition to v8 correctly?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.