Skip to content

Commit

Permalink
Addressed PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <[email protected]>
  • Loading branch information
owaiskazi19 committed Apr 29, 2024
1 parent 7822304 commit d043e85
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public PipelinedRequest resolvePipeline(SearchRequest searchRequest, IndexNameEx
if (searchRequest.pipeline() != null) {
// Named pipeline specified for the request
pipelineId = searchRequest.pipeline();
} else if (state != null && searchRequest.indices() != null) {
} else if (state != null && searchRequest.indices() != null && searchRequest.indices().length != 0) {
// Check for index default pipeline
Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, searchRequest);
for (Index index : concreteIndices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ private static IndexMetadata.Builder indexBuilder(String index) {
}

private static IndexMetadata.Builder indexBuilder(String index, Settings additionalSettings) {
return IndexMetadata.builder(index).settings(settings(additionalSettings));
return IndexMetadata.builder(index).settings(addAdditionalSettings(additionalSettings));
}

private static Settings.Builder settings(Settings additionalSettings) {
private static Settings.Builder addAdditionalSettings(Settings additionalSettings) {
return settings(Version.CURRENT).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(additionalSettings);
Expand Down Expand Up @@ -1629,4 +1629,39 @@ public void testDifferentDefaultPipelineForMultipleIndices() throws Exception {
assertEquals(5, pipelinedRequest.source().size());
}

public void testNoIndexResolveIndexDefaultPipeline() throws Exception {
SearchPipelineService service = createWithProcessors();

SearchPipelineMetadata metadata = new SearchPipelineMetadata(
Map.of(
"p1",
new PipelineConfiguration(
"p1",
new BytesArray("{\"request_processors\" : [ { \"scale_request_size\": { \"scale\" : 2 } } ] }"),
MediaTypeRegistry.JSON
)
)
);
Settings defaultPipelineSetting = Settings.builder()
.put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
.put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0)
.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), Version.CURRENT)
.put(IndexSettings.DEFAULT_SEARCH_PIPELINE.getKey(), "p1")
.build();
IndexMetadata indexMetadata = new IndexMetadata.Builder("my_index").settings(defaultPipelineSetting).build();
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
ClusterState previousState = clusterState;
clusterState = ClusterState.builder(clusterState)
.metadata(Metadata.builder().put(indexMetadata, false).putCustom(SearchPipelineMetadata.TYPE, metadata))
.build();

ClusterChangedEvent cce = new ClusterChangedEvent("", clusterState, previousState);
service.applyClusterState(cce);

SearchRequest searchRequest = new SearchRequest().source(SearchSourceBuilder.searchSource().size(5));
PipelinedRequest pipelinedRequest = syncTransformRequest(service.resolvePipeline(searchRequest, indexNameExpressionResolver));
assertEquals("_none", pipelinedRequest.getPipeline().getId());
assertEquals(5, pipelinedRequest.source().size());
}

}

0 comments on commit d043e85

Please sign in to comment.