Skip to content

Commit

Permalink
Add additional handling in SearchTemplateRequest when simulate is set…
Browse files Browse the repository at this point in the history
… to true (#11591)

Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks authored Dec 19, 2023
1 parent 37dae82 commit 863d453
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Adding slf4j license header to LoggerMessageFormat.java ([#11069](https://github.com/opensearch-project/OpenSearch/pull/11069))
- [BWC and API enforcement] Introduce checks for enforcing the API restrictions ([#11175](https://github.com/opensearch-project/OpenSearch/pull/11175))
- Create separate transport action for render search template action ([#11170](https://github.com/opensearch-project/OpenSearch/pull/11170))
- Add additional handling in SearchTemplateRequest when simulate is set to true ([#11591](https://github.com/opensearch-project/OpenSearch/pull/11591))

### Dependencies
- Bump Lucene from 9.7.0 to 9.8.0 ([10276](https://github.com/opensearch-project/OpenSearch/pull/10276))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,25 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public String[] indices() {
if (request == null) {
return new String[0];
}
return request.indices();
}

@Override
public IndicesOptions indicesOptions() {
if (request == null) {
return SearchRequest.DEFAULT_INDICES_OPTIONS;
}
return request.indicesOptions();
}

@Override
public IndicesRequest indices(String... indices) {
if (request == null) {
return new SearchRequest(new String[0]).indices(indices);
}
return request.indices(indices);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.script.mustache;

import org.opensearch.action.search.SearchRequest;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.script.ScriptType;
import org.opensearch.search.RandomSearchRequestGenerator;
Expand Down Expand Up @@ -110,4 +111,19 @@ public static SearchTemplateRequest createRandomRequest() {
request.setRequest(RandomSearchRequestGenerator.randomSearchRequest(SearchSourceBuilder::searchSource));
return request;
}

public void testSimulatedSearchTemplateRequest() {
SearchTemplateRequest request = new SearchTemplateRequest();
request.setSimulate(true);

assertEquals(0, request.indices().length);
assertEquals(SearchRequest.DEFAULT_INDICES_OPTIONS, request.indicesOptions());
assertEquals(2, request.indices("index1", "index2").indices().length);

SearchTemplateRequest randomRequest = createRandomRequest();
int expectedIndicesLength = randomRequest.indices().length;
request.setSimulate(true);

assertEquals(expectedIndicesLength, randomRequest.indices().length);
}
}

0 comments on commit 863d453

Please sign in to comment.