1616import org .elasticsearch .common .io .stream .StreamInput ;
1717import org .elasticsearch .common .io .stream .StreamOutput ;
1818import org .elasticsearch .common .io .stream .Writeable ;
19+ import org .elasticsearch .common .settings .Setting ;
1920import org .elasticsearch .core .Booleans ;
2021import org .elasticsearch .core .Nullable ;
2122import 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