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

Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Dec 12, 2023
1 parent a8da66c commit 4ad4b0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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 (simulate) {
return new String[0];
}
return request.indices();
}

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

@Override
public IndicesRequest indices(String... indices) {
if (simulate) {
return request;
}
return request.indices(indices);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@

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;
import org.opensearch.search.builder.SearchSourceBuilder;
import org.opensearch.test.AbstractWireSerializingTestCase;
import org.junit.Test;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -110,4 +112,15 @@ public static SearchTemplateRequest createRandomRequest() {
request.setRequest(RandomSearchRequestGenerator.randomSearchRequest(SearchSourceBuilder::searchSource));
return request;
}

@Test
public void testSimulatedSearchTemplateRequest() {
SearchTemplateRequest request = createRandomRequest();
request.setRequest(null);
request.setSimulate(true);

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

0 comments on commit 4ad4b0c

Please sign in to comment.