Skip to content

Commit e2363aa

Browse files
committed
Add changelog
Signed-off-by: Mohit Godwani <[email protected]>
1 parent a1b5efa commit e2363aa

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2020
- [Workload Management] Add Get QueryGroup API Logic ([14709](https://github.com/opensearch-project/OpenSearch/pull/14709))
2121
- [Workload Management] QueryGroup resource tracking framework changes ([#13897](https://github.com/opensearch-project/OpenSearch/pull/13897))
2222
- Add slice execution listeners to SearchOperationListener interface ([#15153](https://github.com/opensearch-project/OpenSearch/pull/15153))
23+
- Add index creation using the context field ([#15290](https://github.com/opensearch-project/OpenSearch/pull/15290))
2324

2425
### Dependencies
2526
- Bump `netty` from 4.1.111.Final to 4.1.112.Final ([#15081](https://github.com/opensearch-project/OpenSearch/pull/15081))

server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
import org.opensearch.index.mapper.DocumentMapper;
9292
import org.opensearch.index.mapper.MapperService;
9393
import org.opensearch.index.mapper.MapperService.MergeReason;
94-
import org.opensearch.index.mapper.Mapping;
9594
import org.opensearch.index.query.QueryShardContext;
9695
import org.opensearch.index.remote.RemoteStoreCustomMetadataResolver;
9796
import org.opensearch.index.remote.RemoteStoreEnums.PathHashAlgorithm;
@@ -101,10 +100,8 @@
101100
import org.opensearch.index.translog.Translog;
102101
import org.opensearch.indices.IndexCreationException;
103102
import org.opensearch.indices.IndicesService;
104-
import org.opensearch.indices.InvalidAliasNameException;
105103
import org.opensearch.indices.InvalidIndexContextException;
106104
import org.opensearch.indices.InvalidIndexNameException;
107-
import org.opensearch.indices.InvalidIndexTemplateException;
108105
import org.opensearch.indices.RemoteStoreSettings;
109106
import org.opensearch.indices.ShardLimitValidator;
110107
import org.opensearch.indices.SystemIndices;
@@ -628,15 +625,18 @@ private ClusterState applyCreateIndexRequestWithV1Templates(
628625
templates.stream().map(IndexTemplateMetadata::name).collect(Collectors.toList())
629626
);
630627

631-
final List<Map<String, Object>> mappings = List.of(Collections.unmodifiableMap(
632-
parseV1Mappings(
633-
request.mappings(),
634-
templates.stream().map(IndexTemplateMetadata::getMappings).collect(toList()),
635-
xContentRegistry
628+
final List<Map<String, Object>> mappings = List.of(
629+
Collections.unmodifiableMap(
630+
parseV1Mappings(
631+
request.mappings(),
632+
templates.stream().map(IndexTemplateMetadata::getMappings).collect(toList()),
633+
xContentRegistry
634+
)
636635
)
637-
));
636+
);
638637
Optional<Template> context = applyContext(request, currentState, mappings);
639-
Settings aggregateSettings = Settings.builder().put(MetadataIndexTemplateService.resolveSettings(templates))
638+
Settings aggregateSettings = Settings.builder()
639+
.put(MetadataIndexTemplateService.resolveSettings(templates))
640640
.put(context.isPresent() ? context.get().settings() : Settings.EMPTY)
641641
.build();
642642

@@ -711,7 +711,8 @@ private ClusterState applyCreateIndexRequestWithV2Template(
711711
);
712712

713713
Optional<Template> context = applyContext(request, currentState, mappings);
714-
Settings aggregateSettings = Settings.builder().put(MetadataIndexTemplateService.resolveSettings(currentState.metadata(), templateName))
714+
Settings aggregateSettings = Settings.builder()
715+
.put(MetadataIndexTemplateService.resolveSettings(currentState.metadata(), templateName))
715716
.put(context.isPresent() ? context.get().settings() : Settings.EMPTY)
716717
.build();
717718

@@ -755,8 +756,11 @@ private ClusterState applyCreateIndexRequestWithV2Template(
755756
);
756757
}
757758

758-
private Optional<Template> applyContext(CreateIndexClusterStateUpdateRequest request, ClusterState currentState,
759-
List<Map<String, Object>> mappings) throws IOException {
759+
private Optional<Template> applyContext(
760+
CreateIndexClusterStateUpdateRequest request,
761+
ClusterState currentState,
762+
List<Map<String, Object>> mappings
763+
) throws IOException {
760764
if (request.context() != null) {
761765
String contextTemplate = MetadataIndexTemplateService.findContextTemplate(currentState.metadata(), request.context());
762766
ComponentTemplate componentTemplate = currentState.metadata().componentTemplates().get(contextTemplate);
@@ -1734,7 +1738,6 @@ static void validateTranslogDurabilitySettings(Settings requestSettings, Cluster
17341738

17351739
}
17361740

1737-
17381741
static void validateContext(CreateIndexClusterStateUpdateRequest request, ClusterState clusterState) {
17391742
final boolean isContextAllowed = FeatureFlags.isEnabled(FeatureFlags.APPLICATION_BASED_CONFIGURATION_TEMPLATES);
17401743

server/src/main/java/org/opensearch/indices/InvalidIndexContextException.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@
1010

1111
import org.opensearch.OpenSearchException;
1212
import org.opensearch.core.common.io.stream.StreamInput;
13-
import org.opensearch.core.common.io.stream.StreamOutput;
1413
import org.opensearch.core.rest.RestStatus;
1514

1615
import java.io.IOException;
1716

17+
/**
18+
* Exception when the context provided in the creation of an index is invalid.
19+
*/
1820
public class InvalidIndexContextException extends OpenSearchException {
1921

22+
/**
23+
*
24+
* @param indexName name of the index
25+
* @param name context name provided
26+
* @param description error message
27+
*/
2028
public InvalidIndexContextException(String indexName, String name, String description) {
2129
super("Invalid context name [{}] provide for index: {}, [{}]", name, indexName, description);
2230
}

0 commit comments

Comments
 (0)