Skip to content

Commit

Permalink
Remove legacy validation of search source in data nodes (elastic#113081)
Browse files Browse the repository at this point in the history
We moved the validation of incoming search requests to data nodes with elastic#105150.
The legacy validation performed on the data nodes was left around for bw comp
reasons, as there could still be coordinating nodes in the cluster not performing
that validation. This is no longer the case in main. This commit removes the
validation in favour of validation already performed while coordinating the
search request.

Relates to elastic#105150
  • Loading branch information
javanna committed Sep 18, 2024
1 parent edfcf16 commit 73c40b9
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions server/src/main/java/org/elasticsearch/search/SearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.elasticsearch.action.ResolvedIndices;
import org.elasticsearch.action.search.CanMatchNodeRequest;
import org.elasticsearch.action.search.CanMatchNodeResponse;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchShardTask;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.action.support.TransportActions;
Expand Down Expand Up @@ -51,7 +50,6 @@
import org.elasticsearch.core.Releasable;
import org.elasticsearch.core.Releasables;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.IndexService;
Expand Down Expand Up @@ -1257,7 +1255,6 @@ private void parseSource(DefaultSearchContext context, SearchSourceBuilder sourc
if (source == null) {
return;
}
validateSearchSource(source, context.scrollContext() != null);
SearchShardTarget shardTarget = context.shardTarget();
SearchExecutionContext searchExecutionContext = context.getSearchExecutionContext();
context.from(source.from());
Expand Down Expand Up @@ -1453,49 +1450,6 @@ private void parseSource(DefaultSearchContext context, SearchSourceBuilder sourc
}
}

/**
* Validates the incoming search request on the data node. These checks have been moved to the coordinating node.
* Validation is still performed on the data nodes to ensure that in a mixed cluster scenario, when the coordinating node is on an older
* version that does not yet perform validation, the shards make up for that.
* This method can be entirely removed in the next major version, when all nodes perform the validation when coordinating a search.
*
* @see SearchRequest#validate()
*/
@UpdateForV9
private static void validateSearchSource(SearchSourceBuilder source, boolean hasScroll) {
if (source.trackTotalHitsUpTo() != null && source.trackTotalHitsUpTo() != SearchContext.TRACK_TOTAL_HITS_ACCURATE && hasScroll) {
throw new IllegalArgumentException("disabling [track_total_hits] is not allowed in a scroll context");
}
if (CollectionUtils.isEmpty(source.searchAfter()) == false) {
if (hasScroll) {
throw new IllegalArgumentException("`search_after` cannot be used in a scroll context.");
}
if (source.from() > 0) {
throw new IllegalArgumentException("`from` parameter must be set to 0 when `search_after` is used.");
}
}
if (source.collapse() != null) {
if (hasScroll) {
throw new IllegalArgumentException("cannot use `collapse` in a scroll context");
}
}
if (source.slice() != null) {
if (source.pointInTimeBuilder() == null && (hasScroll == false)) {
throw new IllegalArgumentException("[slice] can only be used with [scroll] or [point-in-time] requests");
}
}
if (source.storedFields() != null) {
if (source.storedFields().fetchFields() == false) {
if (source.fetchSource() != null && source.fetchSource().fetchSource()) {
throw new IllegalArgumentException("[stored_fields] cannot be disabled if [_source] is requested");
}
if (source.fetchFields() != null) {
throw new IllegalArgumentException("[stored_fields] cannot be disabled when using the [fields] option");
}
}
}
}

/**
* Shortcut ids to load, we load only "from" and up to "size". The phase controller
* handles this as well since the result is always size * shards for Q_T_F
Expand Down

0 comments on commit 73c40b9

Please sign in to comment.