Skip to content

Commit

Permalink
Initial impelmentation of CreateIndex
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <[email protected]>
  • Loading branch information
owaiskazi19 committed Sep 19, 2023
1 parent a574f47 commit edd9c70
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Workflow> execute() throws Exception {

// ActionListener<CreateIndexResponse> 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);
}
}
1 change: 1 addition & 0 deletions src/main/resources/mappings/knn-index-mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit edd9c70

Please sign in to comment.