Skip to content

Commit 5d9ae0e

Browse files
committed
Bypass highlight query terms extraction on empty fields (#32090)
Dealing with empty fields in the highlight phase can slow down the query because the query terms extraction is done independently on each field. This change shortcuts the highlighting performed by the unified highlighter for fields that are not present in the document. In such cases there is nothing to higlight so we don't need to visit the query to build the highligh builder.
1 parent a87ae91 commit 5d9ae0e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

server/src/main/java/org/elasticsearch/search/fetch/subphase/highlight/UnifiedHighlighter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public HighlightField highlight(HighlighterContext highlighterContext) {
7878
fieldValues = fieldValues.stream()
7979
.map((s) -> convertFieldValue(fieldType, s))
8080
.collect(Collectors.toList());
81+
if (fieldValues.size() == 0) {
82+
return null;
83+
}
8184
final IndexSearcher searcher = new IndexSearcher(hitContext.reader());
8285
final CustomUnifiedHighlighter highlighter;
8386
final String fieldValue = mergeFieldValues(fieldValues, MULTIVAL_SEP_CHAR);

0 commit comments

Comments
 (0)