Skip to content

Commit d58c771

Browse files
committed
Fix percolator highlight sub fetch phase to not highlight query twice (#26622)
* Fix percolator highlight sub fetch phase to not highlight query twice The PercolatorHighlightSubFetchPhase does not override hitExecute and since it extends HighlightPhase the search hits are highlighted twice (by the highlight phase and then by the percolator). This does not alter the results, the second highlighting just overrides the first one but this slow down the request because it duplicates the work.
1 parent 5497633 commit d58c771

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

docs/reference/search/request/highlighting.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ Response:
510510
},
511511
"highlight": {
512512
"message": [
513-
"some message with the <em>number</em> <em>1</em>"
513+
" with the <em>number</em> <em>1</em>"
514514
]
515515
}
516516
}

modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorHighlightSubFetchPhase.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@
5050
* Highlighting in the case of the percolate query is a bit different, because the PercolateQuery itself doesn't get highlighted,
5151
* but the source of the PercolateQuery gets highlighted by each hit containing a query.
5252
*/
53-
public final class PercolatorHighlightSubFetchPhase extends HighlightPhase {
53+
final class PercolatorHighlightSubFetchPhase implements FetchSubPhase {
54+
private final HighlightPhase highlightPhase;
5455

55-
public PercolatorHighlightSubFetchPhase(Settings settings, Map<String, Highlighter> highlighters) {
56-
super(settings, highlighters);
56+
PercolatorHighlightSubFetchPhase(Settings settings, Map<String, Highlighter> highlighters) {
57+
this.highlightPhase = new HighlightPhase(settings, highlighters);
5758
}
5859

5960

@@ -97,8 +98,8 @@ public void hitsExecute(SearchContext context, SearchHit[] hits) {
9798
percolatorLeafReaderContext, 0, percolatorIndexSearcher
9899
);
99100
hitContext.cache().clear();
100-
super.hitExecute(subSearchContext, hitContext);
101-
hit.highlightFields().putAll(hitContext.hit().getHighlightFields());
101+
highlightPhase.hitExecute(subSearchContext, hitContext);
102+
hit.getHighlightFields().putAll(hitContext.hit().getHighlightFields());
102103
}
103104
}
104105
}

0 commit comments

Comments
 (0)