Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Create Index Building block #38

Merged
merged 6 commits into from
Sep 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Initial impelmentation of CreateIndex
Signed-off-by: Owais Kazi <owaiskazi19@gmail.com>
owaiskazi19 committed Sep 19, 2023
commit edd9c70cc75ac78b93bdab3d48752bafe3962b1f
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 @@