diff --git a/core/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java index 41b6829994e..1026717adcb 100644 --- a/core/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java @@ -29,7 +29,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.common.lucene.search.MatchNoDocsQuery; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -747,13 +746,6 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder newFieldsBoosts = handleFieldsMatchPattern(context.getMapperService(), fieldsBoosts); Query query = multiMatchQuery.parse(type, newFieldsBoosts, value, minimumShouldMatch); - if (query == null) { - if (newFieldsBoosts.isEmpty()) { - return new MatchNoDocsQuery("[" + NAME + "] could not resolve any field names"); - } else { - return new MatchNoDocsQuery("[" + NAME + "] parsing resolved to null query"); - } - } return query; } diff --git a/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java b/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java index 835ec8e143f..b38d2101163 100644 --- a/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java +++ b/core/src/main/java/org/elasticsearch/index/search/MatchQuery.java @@ -37,6 +37,7 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.lucene.search.MatchNoDocsQuery; import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.unit.Fuzziness; @@ -354,6 +355,9 @@ public class MatchQuery { if (query instanceof FuzzyQuery) { QueryParsers.setRewriteMethod((FuzzyQuery) query, fuzzyRewriteMethod); } + if (query == null) { + return new MatchNoDocsQuery("could not create fuzzy query for field type " + fieldType.name()); + } return query; } catch (RuntimeException e) { if (lenient) { diff --git a/core/src/main/java/org/elasticsearch/index/search/MultiMatchQuery.java b/core/src/main/java/org/elasticsearch/index/search/MultiMatchQuery.java index 115938a2c06..ce6b2cec706 100644 --- a/core/src/main/java/org/elasticsearch/index/search/MultiMatchQuery.java +++ b/core/src/main/java/org/elasticsearch/index/search/MultiMatchQuery.java @@ -23,14 +23,15 @@ import org.apache.lucene.analysis.Analyzer; 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; import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.DisjunctionMaxQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; import org.apache.lucene.util.BytesRef; -import org.apache.lucene.search.BooleanClause.Occur; import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.lucene.search.MatchNoDocsQuery; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.query.AbstractQueryBuilder; @@ -72,14 +73,14 @@ public class MultiMatchQuery extends MatchQuery { } public Query parse(MultiMatchQueryBuilder.Type type, Map fieldNames, Object value, String minimumShouldMatch) throws IOException { + Query result; if (fieldNames.size() == 1) { Map.Entry fieldBoost = fieldNames.entrySet().iterator().next(); Float boostValue = fieldBoost.getValue(); - return parseAndApply(type.matchQueryType(), fieldBoost.getKey(), value, minimumShouldMatch, boostValue); - } - - final float tieBreaker = groupTieBreaker == null ? type.tieBreaker() : groupTieBreaker; - switch (type) { + result = parseAndApply(type.matchQueryType(), fieldBoost.getKey(), value, minimumShouldMatch, boostValue); + } else { + final float tieBreaker = groupTieBreaker == null ? type.tieBreaker() : groupTieBreaker; + switch (type) { case PHRASE: case PHRASE_PREFIX: case BEST_FIELDS: @@ -91,9 +92,12 @@ public class MultiMatchQuery extends MatchQuery { break; default: throw new IllegalStateException("No such type: " + type); + } + final List queries = queryBuilder.buildGroupedQueries(type, fieldNames, value, minimumShouldMatch); + result = queryBuilder.combineGrouped(queries); } - final List queries = queryBuilder.buildGroupedQueries(type, fieldNames, value, minimumShouldMatch); - return queryBuilder.combineGrouped(queries); + assert result != null; + return result; } private QueryBuilder queryBuilder; @@ -127,9 +131,9 @@ public class MultiMatchQuery extends MatchQuery { return parseAndApply(type, field, value, minimumShouldMatch, boostValue); } - public Query combineGrouped(List groupQuery) { + private Query combineGrouped(List groupQuery) { if (groupQuery == null || groupQuery.isEmpty()) { - return null; + return new MatchNoDocsQuery("[multi_match] list of group queries was empty"); } if (groupQuery.size() == 1) { return groupQuery.get(0);