Skip to content

Commit

Permalink
Merge pull request #159 from aodn/revert-158-bugs/read-vocabs-index-s…
Browse files Browse the repository at this point in the history
…chema

Revert "Update method that read the resource's files"
  • Loading branch information
vietnguyengit authored Oct 22, 2024
2 parents d324ea0 + b1d507c commit 088c7d2
Showing 1 changed file with 6 additions and 12 deletions.
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

0 comments on commit 088c7d2

Please sign in to comment.