From f9f2abee7efbae8a872dadd5de04c5682582d652 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Wed, 13 Sep 2017 11:30:13 +0200 Subject: [PATCH 1/2] 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. --- .../percolator/PercolatorHighlightSubFetchPhase.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorHighlightSubFetchPhase.java b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorHighlightSubFetchPhase.java index a0f3c006290d0..44823f9aa012b 100644 --- a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorHighlightSubFetchPhase.java +++ b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorHighlightSubFetchPhase.java @@ -53,13 +53,13 @@ * Highlighting in the case of the percolate query is a bit different, because the PercolateQuery itself doesn't get highlighted, * but the source of the PercolateQuery gets highlighted by each hit containing a query. */ -final class PercolatorHighlightSubFetchPhase extends HighlightPhase { +final class PercolatorHighlightSubFetchPhase implements FetchSubPhase { + private final HighlightPhase highlightPhase; PercolatorHighlightSubFetchPhase(Settings settings, Map highlighters) { - super(settings, highlighters); + this.highlightPhase = new HighlightPhase(settings, highlighters); } - boolean hitsExecutionNeeded(SearchContext context) { // for testing return context.highlight() != null && locatePercolatorQuery(context.query()).isEmpty() == false; } @@ -109,7 +109,7 @@ public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOExcept percolatorLeafReaderContext, slot, percolatorIndexSearcher ); hitContext.cache().clear(); - super.hitExecute(subSearchContext, hitContext); + highlightPhase.hitExecute(subSearchContext, hitContext); for (Map.Entry entry : hitContext.hit().getHighlightFields().entrySet()) { if (percolateQuery.getDocuments().size() == 1) { String hlFieldName; From 0affe178e6fa09c75a222c3c9050dc6d63c710f4 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Wed, 13 Sep 2017 15:53:00 +0200 Subject: [PATCH 2/2] fix docs --- docs/reference/search/request/highlighting.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/search/request/highlighting.asciidoc b/docs/reference/search/request/highlighting.asciidoc index 381bf472dd25b..066df3e6fa053 100644 --- a/docs/reference/search/request/highlighting.asciidoc +++ b/docs/reference/search/request/highlighting.asciidoc @@ -909,7 +909,7 @@ Response: }, "highlight": { "message": [ - "some message with the number 1" + " with the number 1" ] } }