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

Revert "Update method that read the resource's files" #159

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.stream.Collectors;


@Slf4j
Expand All @@ -41,27 +37,25 @@ protected void deleteIndexStore(String indexName) {
}
}

public void createIndexFromMappingJSONFile(String indexMappingFile, String indexName) throws IOException {
public void createIndexFromMappingJSONFile(String indexMappingFile, String indexName) {

// AppConstants.PORTAL_RECORDS_MAPPING_JSON_FILE
log.info("Reading index schema definition from JSON file: {}", indexMappingFile);

Resource resource = new ClassPathResource("config_files/" + indexMappingFile);
InputStream fStream = resource.getInputStream();
ClassPathResource resource = new ClassPathResource("config_files/" + indexMappingFile);

// delete the existing index if found first
this.deleteIndexStore(indexName);

log.info("Creating index: {}", indexName);
try ( BufferedReader reader = new BufferedReader(
new InputStreamReader(fStream)) ) {
try (InputStream input = resource.getInputStream()) {
CreateIndexRequest req = CreateIndexRequest.of(b -> b
.index(indexName)
.withJson(reader)
.withJson(input)
);
CreateIndexResponse response = portalElasticsearchClient.indices().create(req);
log.info(response.toString());
} catch (ElasticsearchException | IOException e) {
}
catch (ElasticsearchException | IOException e) {
log.error("Failed to create index: {} | {}", indexName, e.getMessage());
throw new CreateIndexException("Failed to elastic index from schema file: " + indexName + " | " + e.getMessage());
}
Expand Down
Loading