Skip to content

Commit

Permalink
Fix rest validation of search request using a PIT (#71688)
Browse files Browse the repository at this point in the history
The rest validation of the search request ensures that the indices options
are set to the default value. However, the comparison is too strict and should
use equals since we create a new IndicesOption object when parsing from http or transport.

Closes #69974
  • Loading branch information
jimczi committed Apr 20, 2021
1 parent bb81340 commit 9fb69ba
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public static void writeSearchRequestParams(SearchRequest request, XContentBuild
if (request.indices() != null) {
xContentBuilder.field("index", request.indices());
}
if (request.indicesOptions() != null && request.indicesOptions() != SearchRequest.DEFAULT_INDICES_OPTIONS) {
if (request.indicesOptions().equals(SearchRequest.DEFAULT_INDICES_OPTIONS) == false) {
WildcardStates.toXContent(request.indicesOptions().getExpandWildcards(), xContentBuilder);
xContentBuilder.field("ignore_unavailable", request.indicesOptions().ignoreUnavailable());
xContentBuilder.field("allow_no_indices", request.indicesOptions().allowNoIndices());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ && request().indicesOptions() != IndicesOptions.strictExpandOpenAndForbidClosed(
* same order as the search requests.
*/
public MultiSearchRequestBuilder add(SearchRequestBuilder request) {
if (request.request().indicesOptions() == SearchRequest.DEFAULT_INDICES_OPTIONS
&& request().indicesOptions() != SearchRequest.DEFAULT_INDICES_OPTIONS) {
if (request.request().indicesOptions().equals(SearchRequest.DEFAULT_INDICES_OPTIONS)
&& request().indicesOptions().equals(SearchRequest.DEFAULT_INDICES_OPTIONS) == false) {
request.request().indicesOptions(request().indicesOptions());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.action.search.SearchRequest.DEFAULT_INDICES_OPTIONS;
import static org.elasticsearch.common.unit.TimeValue.parseTimeValue;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;
Expand Down Expand Up @@ -312,7 +313,7 @@ static void preparePointInTime(SearchRequest request, RestRequest restRequest, N
if (request.indices().length > 0) {
validationException = addValidationError("[indices] cannot be used with point in time", validationException);
}
if (request.indicesOptions() != SearchRequest.DEFAULT_INDICES_OPTIONS) {
if (request.indicesOptions().equals(DEFAULT_INDICES_OPTIONS) == false) {
validationException = addValidationError("[indicesOptions] cannot be used with point in time", validationException);
}
if (request.routing() != null) {
Expand Down

0 comments on commit 9fb69ba

Please sign in to comment.