Skip to content

Commit f699cb9

Browse files
authored
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 d596447 commit f699cb9

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

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public HighlightField highlight(HighlighterContext highlighterContext) {
7676
fieldValues = fieldValues.stream()
7777
.map((s) -> convertFieldValue(fieldType, s))
7878
.collect(Collectors.toList());
79+
if (fieldValues.size() == 0) {
80+
return null;
81+
}
7982
final IndexSearcher searcher = new IndexSearcher(hitContext.reader());
8083
final CustomUnifiedHighlighter highlighter;
8184
final String fieldValue = mergeFieldValues(fieldValues, MULTIVAL_SEP_CHAR);

0 commit comments

Comments
 (0)