Skip to content

Commit 36bf851

Browse files
committed
Add search.default_exclude_vectors setting as fallback
1 parent 60245c9 commit 36bf851

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
import org.elasticsearch.search.SearchService;
127127
import org.elasticsearch.search.aggregations.MultiBucketConsumerService;
128128
import org.elasticsearch.search.aggregations.metrics.TDigestExecutionHint;
129+
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
129130
import org.elasticsearch.search.fetch.subphase.highlight.FastVectorHighlighter;
130131
import org.elasticsearch.snapshots.InternalSnapshotsInfoService;
131132
import org.elasticsearch.snapshots.RestoreService;
@@ -547,6 +548,7 @@ public void apply(Settings value, Settings current, Settings previous) {
547548
ThreadPool.SLOW_SCHEDULER_TASK_WARN_THRESHOLD_SETTING,
548549
ThreadPool.WRITE_THREAD_POOLS_EWMA_ALPHA_SETTING,
549550
FastVectorHighlighter.SETTING_TV_HIGHLIGHT_MULTI_VALUE,
551+
FetchSourceContext.DEFAULT_SOURCE_EXCLUDE_VECTORS,
550552
Node.BREAKER_TYPE_KEY,
551553
OperationRouting.USE_ADAPTIVE_REPLICA_SELECTION_SETTING,
552554
IndexGraveyard.SETTING_MAX_TOMBSTONES,

server/src/main/java/org/elasticsearch/search/SearchService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
import org.elasticsearch.search.fetch.ShardFetchRequest;
103103
import org.elasticsearch.search.fetch.subphase.FetchDocValuesContext;
104104
import org.elasticsearch.search.fetch.subphase.FetchFieldsContext;
105+
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
105106
import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField;
106107
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
107108
import org.elasticsearch.search.internal.AliasFilter;
@@ -445,6 +446,9 @@ public SearchService(
445446
clusterService.getClusterSettings()
446447
.addSettingsUpdateConsumer(MEMORY_ACCOUNTING_BUFFER_SIZE, newValue -> this.memoryAccountingBufferSize = newValue.getBytes());
447448
prewarmingMaxPoolFactorThreshold = PREWARMING_THRESHOLD_THREADPOOL_SIZE_FACTOR_POOL_SIZE.get(settings);
449+
450+
clusterService.getClusterSettings()
451+
.initializeAndWatch(FetchSourceContext.DEFAULT_SOURCE_EXCLUDE_VECTORS, FetchSourceContext::setDefaultSourceExcludeVectors);
448452
}
449453

450454
public CircuitBreaker getCircuitBreaker() {

server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchSourceContext.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.common.io.stream.StreamInput;
1717
import org.elasticsearch.common.io.stream.StreamOutput;
1818
import org.elasticsearch.common.io.stream.Writeable;
19+
import org.elasticsearch.common.settings.Setting;
1920
import org.elasticsearch.core.Booleans;
2021
import org.elasticsearch.core.Nullable;
2122
import org.elasticsearch.rest.RestRequest;
@@ -40,6 +41,14 @@ public class FetchSourceContext implements Writeable, ToXContentObject {
4041
public static final ParseField INCLUDES_FIELD = new ParseField("includes", "include");
4142
public static final ParseField EXCLUDES_FIELD = new ParseField("excludes", "exclude");
4243

44+
public static final Setting<Boolean> DEFAULT_SOURCE_EXCLUDE_VECTORS = Setting.boolSetting(
45+
"search.default_exclude_vectors",
46+
true,
47+
Setting.Property.NodeScope,
48+
Setting.Property.Dynamic
49+
);
50+
private static volatile Boolean defaultSourceExcludeVectors;
51+
4352
public static final FetchSourceContext FETCH_SOURCE = new FetchSourceContext(true, null, Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY);
4453
public static final FetchSourceContext FETCH_ALL_SOURCE = new FetchSourceContext(true, false, Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY);
4554

@@ -89,6 +98,14 @@ public static FetchSourceContext readFrom(StreamInput in) throws IOException {
8998
return of(fetchSource, excludeVectors, includes, excludes);
9099
}
91100

101+
public static void setDefaultSourceExcludeVectors(boolean defaultSourceExcludeVectors) {
102+
if (defaultSourceExcludeVectors) {
103+
FetchSourceContext.defaultSourceExcludeVectors = null;
104+
} else {
105+
FetchSourceContext.defaultSourceExcludeVectors = false;
106+
}
107+
}
108+
92109
@Override
93110
public void writeTo(StreamOutput out) throws IOException {
94111
out.writeBoolean(fetchSource);
@@ -157,7 +174,7 @@ public static FetchSourceContext parseFromRestRequest(RestRequest request) {
157174
sourceExcludes = Strings.splitStringByCommaToArray(sExcludes);
158175
}
159176

160-
Boolean excludeVectors = request.paramAsBoolean("_source_exclude_vectors", null);
177+
Boolean excludeVectors = request.paramAsBoolean("_source_exclude_vectors", defaultSourceExcludeVectors);
161178

162179
if (excludeVectors != null || fetchSource != null || sourceIncludes != null || sourceExcludes != null) {
163180
return FetchSourceContext.of(fetchSource == null || fetchSource, excludeVectors, sourceIncludes, sourceExcludes);

0 commit comments

Comments
 (0)