diff --git a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index 9c2d6fab10368..4aa802caaafc5 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -126,6 +126,7 @@ import org.elasticsearch.search.SearchService; import org.elasticsearch.search.aggregations.MultiBucketConsumerService; import org.elasticsearch.search.aggregations.metrics.TDigestExecutionHint; +import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import org.elasticsearch.search.fetch.subphase.highlight.FastVectorHighlighter; import org.elasticsearch.snapshots.InternalSnapshotsInfoService; import org.elasticsearch.snapshots.RestoreService; @@ -547,6 +548,7 @@ public void apply(Settings value, Settings current, Settings previous) { ThreadPool.SLOW_SCHEDULER_TASK_WARN_THRESHOLD_SETTING, ThreadPool.WRITE_THREAD_POOLS_EWMA_ALPHA_SETTING, FastVectorHighlighter.SETTING_TV_HIGHLIGHT_MULTI_VALUE, + FetchSourceContext.DEFAULT_SOURCE_EXCLUDE_VECTORS, Node.BREAKER_TYPE_KEY, OperationRouting.USE_ADAPTIVE_REPLICA_SELECTION_SETTING, IndexGraveyard.SETTING_MAX_TOMBSTONES, diff --git a/server/src/main/java/org/elasticsearch/search/SearchService.java b/server/src/main/java/org/elasticsearch/search/SearchService.java index 9cca55f2ec748..8129301079758 100644 --- a/server/src/main/java/org/elasticsearch/search/SearchService.java +++ b/server/src/main/java/org/elasticsearch/search/SearchService.java @@ -102,6 +102,7 @@ import org.elasticsearch.search.fetch.ShardFetchRequest; import org.elasticsearch.search.fetch.subphase.FetchDocValuesContext; import org.elasticsearch.search.fetch.subphase.FetchFieldsContext; +import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField; import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; import org.elasticsearch.search.internal.AliasFilter; @@ -445,6 +446,9 @@ public SearchService( clusterService.getClusterSettings() .addSettingsUpdateConsumer(MEMORY_ACCOUNTING_BUFFER_SIZE, newValue -> this.memoryAccountingBufferSize = newValue.getBytes()); prewarmingMaxPoolFactorThreshold = PREWARMING_THRESHOLD_THREADPOOL_SIZE_FACTOR_POOL_SIZE.get(settings); + + clusterService.getClusterSettings() + .initializeAndWatch(FetchSourceContext.DEFAULT_SOURCE_EXCLUDE_VECTORS, FetchSourceContext::setDefaultSourceExcludeVectors); } public CircuitBreaker getCircuitBreaker() { diff --git a/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java b/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java index f35794c0438c3..d62a16c66280c 100644 --- a/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java +++ b/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java @@ -16,6 +16,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.core.Booleans; import org.elasticsearch.core.Nullable; import org.elasticsearch.rest.RestRequest; @@ -40,6 +41,14 @@ public class FetchSourceContext implements Writeable, ToXContentObject { public static final ParseField INCLUDES_FIELD = new ParseField("includes", "include"); public static final ParseField EXCLUDES_FIELD = new ParseField("excludes", "exclude"); + public static final Setting DEFAULT_SOURCE_EXCLUDE_VECTORS = Setting.boolSetting( + "search.default_exclude_vectors", + true, + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); + private static volatile Boolean defaultSourceExcludeVectors; + public static final FetchSourceContext FETCH_SOURCE = new FetchSourceContext(true, null, Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY); public static final FetchSourceContext FETCH_ALL_SOURCE = new FetchSourceContext(true, false, Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY); @@ -89,6 +98,14 @@ public static FetchSourceContext readFrom(StreamInput in) throws IOException { return of(fetchSource, excludeVectors, includes, excludes); } + public static void setDefaultSourceExcludeVectors(boolean defaultSourceExcludeVectors) { + if (defaultSourceExcludeVectors) { + FetchSourceContext.defaultSourceExcludeVectors = null; + } else { + FetchSourceContext.defaultSourceExcludeVectors = false; + } + } + @Override public void writeTo(StreamOutput out) throws IOException { out.writeBoolean(fetchSource); @@ -157,7 +174,7 @@ public static FetchSourceContext parseFromRestRequest(RestRequest request) { sourceExcludes = Strings.splitStringByCommaToArray(sExcludes); } - Boolean excludeVectors = request.paramAsBoolean("_source_exclude_vectors", null); + Boolean excludeVectors = request.paramAsBoolean("_source_exclude_vectors", defaultSourceExcludeVectors); if (excludeVectors != null || fetchSource != null || sourceIncludes != null || sourceExcludes != null) { return FetchSourceContext.of(fetchSource == null || fetchSource, excludeVectors, sourceIncludes, sourceExcludes);