-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial impelmentation of CreateIndex
Signed-off-by: Owais Kazi <[email protected]>
- Loading branch information
1 parent
0f0b65d
commit b509dc2
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/main/java/org/opensearch/flowframework/workflow/CreateIndexStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|