From b1d507c519677b5707a0eedeaff95de74476d3b7 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Date: Tue, 22 Oct 2024 16:45:22 +1100 Subject: [PATCH] Revert "Update method that read the resource's files" --- .../service/ElasticSearchIndexService.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/indexer/src/main/java/au/org/aodn/esindexer/service/ElasticSearchIndexService.java b/indexer/src/main/java/au/org/aodn/esindexer/service/ElasticSearchIndexService.java index e933e73d..16603a43 100644 --- a/indexer/src/main/java/au/org/aodn/esindexer/service/ElasticSearchIndexService.java +++ b/indexer/src/main/java/au/org/aodn/esindexer/service/ElasticSearchIndexService.java @@ -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 @@ -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()); }