Skip to content

Commit 9fb69ba

Browse files
committed
Fix rest validation of search request using a PIT (#71688)
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
1 parent bb81340 commit 9fb69ba

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public static void writeSearchRequestParams(SearchRequest request, XContentBuild
315315
if (request.indices() != null) {
316316
xContentBuilder.field("index", request.indices());
317317
}
318-
if (request.indicesOptions() != null && request.indicesOptions() != SearchRequest.DEFAULT_INDICES_OPTIONS) {
318+
if (request.indicesOptions().equals(SearchRequest.DEFAULT_INDICES_OPTIONS) == false) {
319319
WildcardStates.toXContent(request.indicesOptions().getExpandWildcards(), xContentBuilder);
320320
xContentBuilder.field("ignore_unavailable", request.indicesOptions().ignoreUnavailable());
321321
xContentBuilder.field("allow_no_indices", request.indicesOptions().allowNoIndices());

server/src/main/java/org/elasticsearch/action/search/MultiSearchRequestBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ && request().indicesOptions() != IndicesOptions.strictExpandOpenAndForbidClosed(
4444
* same order as the search requests.
4545
*/
4646
public MultiSearchRequestBuilder add(SearchRequestBuilder request) {
47-
if (request.request().indicesOptions() == SearchRequest.DEFAULT_INDICES_OPTIONS
48-
&& request().indicesOptions() != SearchRequest.DEFAULT_INDICES_OPTIONS) {
47+
if (request.request().indicesOptions().equals(SearchRequest.DEFAULT_INDICES_OPTIONS)
48+
&& request().indicesOptions().equals(SearchRequest.DEFAULT_INDICES_OPTIONS) == false) {
4949
request.request().indicesOptions(request().indicesOptions());
5050
}
5151

server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import static java.util.Arrays.asList;
4949
import static java.util.Collections.unmodifiableList;
5050
import static org.elasticsearch.action.ValidateActions.addValidationError;
51+
import static org.elasticsearch.action.search.SearchRequest.DEFAULT_INDICES_OPTIONS;
5152
import static org.elasticsearch.common.unit.TimeValue.parseTimeValue;
5253
import static org.elasticsearch.rest.RestRequest.Method.GET;
5354
import static org.elasticsearch.rest.RestRequest.Method.POST;
@@ -312,7 +313,7 @@ static void preparePointInTime(SearchRequest request, RestRequest restRequest, N
312313
if (request.indices().length > 0) {
313314
validationException = addValidationError("[indices] cannot be used with point in time", validationException);
314315
}
315-
if (request.indicesOptions() != SearchRequest.DEFAULT_INDICES_OPTIONS) {
316+
if (request.indicesOptions().equals(DEFAULT_INDICES_OPTIONS) == false) {
316317
validationException = addValidationError("[indicesOptions] cannot be used with point in time", validationException);
317318
}
318319
if (request.routing() != null) {

0 commit comments

Comments
 (0)