diff --git a/server/src/main/java/org/elasticsearch/index/search/MatchQueryParser.java b/server/src/main/java/org/elasticsearch/index/search/MatchQueryParser.java index 17ea7e2fd3472..70dc765445c13 100644 --- a/server/src/main/java/org/elasticsearch/index/search/MatchQueryParser.java +++ b/server/src/main/java/org/elasticsearch/index/search/MatchQueryParser.java @@ -248,9 +248,9 @@ public Query parse(Type type, String fieldName, Object value) throws IOException switch (type) { case BOOLEAN: if (commonTermsCutoff == null) { - query = builder.createBooleanQuery(fieldName, value.toString(), occur); + query = builder.createBooleanQuery(resolvedFieldName, value.toString(), occur); } else { - query = createCommonTermsQuery(builder, fieldName, value.toString(), occur, occur, commonTermsCutoff); + query = createCommonTermsQuery(builder, resolvedFieldName, value.toString(), occur, occur, commonTermsCutoff); } break; case BOOLEAN_PREFIX: diff --git a/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java index 5961e29ce2d5b..e82accde16129 100644 --- a/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java @@ -44,6 +44,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -488,16 +489,18 @@ public void testMultiWordSynonymsPhrase() throws Exception { assertEquals(expected, actual); } - public void testAliasWithSynonyms() throws Exception { - final MatchQueryParser matchQueryParser = new MatchQueryParser(createSearchExecutionContext()); + MatchQueryParser matchQueryParser = new MatchQueryParser(createSearchExecutionContext()); matchQueryParser.setAnalyzer(new MockSynonymAnalyzer()); - final Query actual = matchQueryParser.parse(Type.PHRASE, TEXT_ALIAS_FIELD_NAME, "dogs"); - Query expected = new SynonymQuery.Builder(TEXT_FIELD_NAME) - .addTerm(new Term(TEXT_FIELD_NAME, "dogs")) - .addTerm(new Term(TEXT_FIELD_NAME, "dog")) - .build(); - assertEquals(expected, actual); + + for (Type type : Arrays.asList(Type.BOOLEAN, Type.PHRASE)) { + Query actual = matchQueryParser.parse(type, TEXT_ALIAS_FIELD_NAME, "dogs"); + Query expected = new SynonymQuery.Builder(TEXT_FIELD_NAME) + .addTerm(new Term(TEXT_FIELD_NAME, "dogs")) + .addTerm(new Term(TEXT_FIELD_NAME, "dog")) + .build(); + assertEquals(expected, actual); + } } public void testMaxBooleanClause() {