diff --git a/core/src/main/java/org/elasticsearch/common/lucene/search/MultiPhrasePrefixQuery.java b/core/src/main/java/org/elasticsearch/common/lucene/search/MultiPhrasePrefixQuery.java
index dbfc1f0af11..b8e1039b2df 100644
--- a/core/src/main/java/org/elasticsearch/common/lucene/search/MultiPhrasePrefixQuery.java
+++ b/core/src/main/java/org/elasticsearch/common/lucene/search/MultiPhrasePrefixQuery.java
@@ -164,6 +164,11 @@ public class MultiPhrasePrefixQuery extends Query {
}
}
if (terms.isEmpty()) {
+ if (sizeMinus1 == 0) {
+ // no prefix and the phrase query is empty
+ return Queries.newMatchNoDocsQuery("No terms supplied for " + MultiPhrasePrefixQuery.class.getName());
+ }
+
// if the terms does not exist we could return a MatchNoDocsQuery but this would break the unified highlighter
// which rewrites query with an empty reader.
return new BooleanQuery.Builder()
diff --git a/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java b/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java
index c8c0314805a..f7f9bbaeb45 100644
--- a/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java
+++ b/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java
@@ -1462,7 +1462,6 @@ public class HighlighterSearchIT extends ESIntegTestCase {
assertHighlight(searchResponse, 0, "field0", 0, 1, equalTo("The quick brown fox jumps over the lazy dog"));
-
source = searchSource()
.query(matchPhrasePrefixQuery("field0", "quick bro"))
.highlighter(highlight().field("field0").order("score").preTags("").postTags("").highlighterType(type));
@@ -1472,6 +1471,21 @@ public class HighlighterSearchIT extends ESIntegTestCase {
assertHighlight(searchResponse, 0, "field0", 0, 1, equalTo("The quick brown fox jumps over the lazy dog"));
logger.info("--> highlighting and searching on field1");
+ source = searchSource()
+ .query(boolQuery()
+ .should(matchPhrasePrefixQuery("field1", "test"))
+ .should(matchPhrasePrefixQuery("field1", "bro"))
+ )
+ .highlighter(highlight().field("field1").order("score").preTags("").postTags("").highlighterType(type));
+
+ searchResponse = client().search(searchRequest("test").source(source)).actionGet();
+ assertThat(searchResponse.getHits().totalHits, equalTo(2L));
+ for (int i = 0; i < 2; i++) {
+ assertHighlight(searchResponse, i, "field1", 0, 1, anyOf(
+ equalTo("The quick browse button is a fancy thing, right bro?"),
+ equalTo("The quick brown fox jumps over the lazy dog")));
+ }
+
source = searchSource()
.query(matchPhrasePrefixQuery("field1", "quick bro"))
.highlighter(highlight().field("field1").order("score").preTags("").postTags("").highlighterType(type));
diff --git a/core/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java b/core/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java
index 65a54feabbe..09a9a9aa945 100644
--- a/core/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java
+++ b/core/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java
@@ -280,9 +280,7 @@ public class SimpleValidateQueryIT extends ESIntegTestCase {
assertExplanations(QueryBuilders.matchPhrasePrefixQuery("field", "ju"),
Arrays.asList(
equalTo("field:jumps"),
- equalTo("+MatchNoDocsQuery(\"empty MultiPhraseQuery\") +MatchNoDocsQuery(\"No " +
- "terms supplied for org.elasticsearch.common.lucene.search." +
- "MultiPhrasePrefixQuery\")")
+ equalTo("field:\"ju*\"")
), true, true);
}