From 48ef215b21b0ff2d409aa792983f21600fbae53d Mon Sep 17 00:00:00 2001 From: david-leifker <114954101+david-leifker@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:51:11 -0500 Subject: [PATCH] perf(search): reduce highlight fragments (#11349) --- .../query/request/AutocompleteRequestHandler.java | 10 ++++++---- .../query/request/SearchRequestHandler.java | 11 ++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/metadata-io/src/main/java/com/linkedin/metadata/search/elasticsearch/query/request/AutocompleteRequestHandler.java b/metadata-io/src/main/java/com/linkedin/metadata/search/elasticsearch/query/request/AutocompleteRequestHandler.java index 0bca269c14dbac..24598d7fdaadb8 100644 --- a/metadata-io/src/main/java/com/linkedin/metadata/search/elasticsearch/query/request/AutocompleteRequestHandler.java +++ b/metadata-io/src/main/java/com/linkedin/metadata/search/elasticsearch/query/request/AutocompleteRequestHandler.java @@ -226,10 +226,12 @@ private static BoolQueryBuilder defaultQuery( // Get HighlightBuilder to highlight the matched field private HighlightBuilder getHighlights(@Nullable String field) { - HighlightBuilder highlightBuilder = new HighlightBuilder(); - // Don't set tags to get the original field value - highlightBuilder.preTags(""); - highlightBuilder.postTags(""); + HighlightBuilder highlightBuilder = + new HighlightBuilder() + // Don't set tags to get the original field value + .preTags("") + .postTags("") + .numOfFragments(1); // Check for each field name and any subfields getAutocompleteFields(field) .forEach( diff --git a/metadata-io/src/main/java/com/linkedin/metadata/search/elasticsearch/query/request/SearchRequestHandler.java b/metadata-io/src/main/java/com/linkedin/metadata/search/elasticsearch/query/request/SearchRequestHandler.java index 748d21c985d006..91cfeaf43a4cb4 100644 --- a/metadata-io/src/main/java/com/linkedin/metadata/search/elasticsearch/query/request/SearchRequestHandler.java +++ b/metadata-io/src/main/java/com/linkedin/metadata/search/elasticsearch/query/request/SearchRequestHandler.java @@ -366,11 +366,12 @@ public QueryBuilder getQuery( @VisibleForTesting public HighlightBuilder getHighlights() { - HighlightBuilder highlightBuilder = new HighlightBuilder(); - - // Don't set tags to get the original field value - highlightBuilder.preTags(""); - highlightBuilder.postTags(""); + HighlightBuilder highlightBuilder = + new HighlightBuilder() + // Don't set tags to get the original field value + .preTags("") + .postTags("") + .numOfFragments(1); // Check for each field name and any subfields defaultQueryFieldNames.stream()