diff --git a/x-pack/plugin/search-business-rules/src/main/java/org/apache/lucene/search/CappedScoreQuery.java b/x-pack/plugin/search-business-rules/src/main/java/org/apache/lucene/search/CappedScoreQuery.java index 9a8f4fbe38bd1..ed8ede57b4d52 100644 --- a/x-pack/plugin/search-business-rules/src/main/java/org/apache/lucene/search/CappedScoreQuery.java +++ b/x-pack/plugin/search-business-rules/src/main/java/org/apache/lucene/search/CappedScoreQuery.java @@ -33,6 +33,11 @@ public Query getQuery() { return query; } + @Override + public void visit(QueryVisitor visitor) { + query.visit(visitor.getSubVisitor(BooleanClause.Occur.MUST, this)); + } + @Override public Query rewrite(IndexReader reader) throws IOException { Query rewritten = query.rewrite(reader); diff --git a/x-pack/plugin/search-business-rules/src/test/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilderIT.java b/x-pack/plugin/search-business-rules/src/test/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilderIT.java index 6aa69a2325a8f..6867cddaf1530 100644 --- a/x-pack/plugin/search-business-rules/src/test/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilderIT.java +++ b/x-pack/plugin/search-business-rules/src/test/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilderIT.java @@ -17,12 +17,15 @@ import org.elasticsearch.index.query.QueryStringQueryBuilder; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; +import org.elasticsearch.search.fetch.subphase.highlight.HighlightField; import org.elasticsearch.test.ESIntegTestCase; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import static org.elasticsearch.action.search.SearchType.DFS_QUERY_THEN_FETCH; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; @@ -196,5 +199,29 @@ public void testExplain() throws Exception { } + + public void testHighlight() throws Exception { + // Issue raised in https://github.com/elastic/elasticsearch/issues/53699 + assertAcked(prepareCreate("test").setMapping( + jsonBuilder().startObject().startObject("_doc").startObject("properties").startObject("field1") + .field("analyzer", "whitespace").field("type", "text").endObject().endObject().endObject().endObject())); + ensureGreen(); + client().prepareIndex("test").setId("1").setSource("field1", "the quick brown fox").get(); + refresh(); + + PinnedQueryBuilder pqb = new PinnedQueryBuilder(QueryBuilders.matchQuery("field1", "the quick brown").operator(Operator.OR), "2"); + + HighlightBuilder testHighlighter = new HighlightBuilder(); + testHighlighter.field("field1"); + SearchResponse searchResponse = client().prepareSearch().setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery(pqb) + .highlighter(testHighlighter) + .setExplain(true).get(); + assertHitCount(searchResponse, 1); + Map highlights = searchResponse.getHits().getHits()[0].getHighlightFields(); + assertThat(highlights.size(), equalTo(1)); + HighlightField highlight = highlights.get("field1"); + assertThat(highlight.fragments()[0].toString(), equalTo("the quick brown fox")); + } } +