diff --git a/src/main/java/org/opensearch/flowframework/workflow/CreateIndexStep.java b/src/main/java/org/opensearch/flowframework/workflow/CreateIndexStep.java new file mode 100644 index 000000000..3786313fb --- /dev/null +++ b/src/main/java/org/opensearch/flowframework/workflow/CreateIndexStep.java @@ -0,0 +1,45 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ +package org.opensearch.flowframework.workflow; + +import com.google.common.base.Charsets; +import com.google.common.io.Resources; +import org.opensearch.action.admin.indices.create.CreateIndexRequest; +import org.opensearch.client.AdminClient; +import org.opensearch.common.xcontent.XContentType; + +import java.io.IOException; +import java.net.URL; +import java.util.concurrent.CompletableFuture; + +public class CreateIndexStep implements Workflow { + + AdminClient adminClient; + + @Override + public CompletableFuture execute() throws Exception { + + // ActionListener actionListener + CreateIndexRequest request = new CreateIndexRequest(indexName).mapping(getIndexMappings(fileName), XContentType.JSON) + .settings(settings); + adminClient.indices().create(request, actionListener); + + } + + /** + * Get index mapping json content. + * + * @return index mapping + * @throws IOException IOException if mapping file can't be read correctly + */ + public static String getIndexMappings(String mappingFileName) throws IOException { + URL url = CreateIndexStep.class.getClassLoader().getResource(mappingFileName); + return Resources.toString(url, Charsets.UTF_8); + } +} diff --git a/src/main/resources/mappings/knn-index-mapping.json b/src/main/resources/mappings/knn-index-mapping.json new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/src/main/resources/mappings/knn-index-mapping.json @@ -0,0 +1 @@ +