Skip to content

Commit

Permalink
Set include_vectors to the default value for old clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikep86 committed Sep 27, 2024
1 parent 75c8a4e commit e82e283
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortBuilder;
import org.elasticsearch.xcontent.NamedXContentRegistry;
Expand Down Expand Up @@ -141,7 +142,18 @@ static Request initialSearch(SearchRequest searchRequest, BytesReference query,
}

if (searchRequest.source().fetchSource() != null) {
entity.field("_source", searchRequest.source().fetchSource());
FetchSourceContext fetchSource = searchRequest.source().fetchSource();
if (remoteVersion.before(Version.V_8_16_0)) {
// Versions before 8.16 do not support the include_vectors param. They include all vector fields by default.
// Set the include_vectors param to the default value so that it is not included in XContent.
fetchSource = FetchSourceContext.of(
fetchSource.fetchSource(),
fetchSource.includes(),
fetchSource.excludes(),
FetchSourceContext.DEFAULT_INCLUDE_VECTORS
);
}
entity.field("_source", fetchSource);
} else {
if (remoteVersion.onOrAfter(Version.fromId(1000099))) {
// Versions before 1.0 don't support `"_source": true` so we have to ask for the source as a stored field.
Expand Down

0 comments on commit e82e283

Please sign in to comment.