From ead6ffce54ceed45b347dd6d8a1021d46b634cee Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Tue, 2 Oct 2018 14:53:26 +0200 Subject: [PATCH] Fix cross fields mode of the query_string query (#34216) This change fixes a bug in the cross fields mode of the `query_string` query. The multi fields query builder must be reseted before parsing in order to clear the list of expanded fields coming from the previous text block. Closes #34215 --- .../index/search/MultiMatchQuery.java | 4 +- .../query/QueryStringQueryBuilderTests.java | 70 +++++++++++++++---- 2 files changed, 59 insertions(+), 15 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/search/MultiMatchQuery.java b/server/src/main/java/org/elasticsearch/index/search/MultiMatchQuery.java index 89cebf38a40..63e88ae19a9 100644 --- a/server/src/main/java/org/elasticsearch/index/search/MultiMatchQuery.java +++ b/server/src/main/java/org/elasticsearch/index/search/MultiMatchQuery.java @@ -67,7 +67,9 @@ public class MultiMatchQuery extends MatchQuery { } public Query parse(MultiMatchQueryBuilder.Type type, Map fieldNames, Object value, String minimumShouldMatch) throws IOException { - Query result; + final Query result; + // reset query builder + queryBuilder = null; if (fieldNames.size() == 1) { Map.Entry fieldBoost = fieldNames.entrySet().iterator().next(); Float boostValue = fieldBoost.getValue(); diff --git a/server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java index 1cc058eb724..ee56d07ca65 100644 --- a/server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.query; import org.apache.lucene.analysis.MockSynonymAnalyzer; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.BlendedTermQuery; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; @@ -1195,20 +1196,23 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase