Loading src/main/java/es/redmic/es/common/repository/RBaseESRepository.java +6 −17 Original line number Diff line number Diff line Loading @@ -97,6 +97,10 @@ public abstract class RBaseESRepository<TModel extends BaseES<?>> implements IRB protected static final Logger LOGGER = LoggerFactory.getLogger(RBaseESRepository.class); private static final String UPDATE_NESTED_PROPERTY_SCRIPT_PATH = "/scripts/update-nested-property.txt"; private static final String UPDATE_PROPERTY_SCRIPT_PATH = "/scripts/update-property.txt"; @Value("${redmic.elasticsearch.check.mappings}") private boolean checkMappings; Loading Loading @@ -957,13 +961,11 @@ public abstract class RBaseESRepository<TModel extends BaseES<?>> implements IRB protected String getUpdatePropertyScript() { // TODO: return inline script return ""; return ElasticSearchUtils.getScriptFile(UPDATE_PROPERTY_SCRIPT_PATH); } protected String getUpdateNestedPropertyScript() { // TODO: return inline script return ""; return ElasticSearchUtils.getScriptFile(UPDATE_NESTED_PROPERTY_SCRIPT_PATH); } protected abstract String[] getDefaultSearchFields(); Loading @@ -990,17 +992,4 @@ public abstract class RBaseESRepository<TModel extends BaseES<?>> implements IRB public String getType() { return TYPE; } protected String getScriptFile(String mappingFilePath) { try { InputStream resource = new ClassPathResource(mappingFilePath).getInputStream(); return IOUtils.toString(resource, Charset.forName(StandardCharsets.UTF_8.name())); } catch (IOException e) { e.printStackTrace(); LOGGER.error("Error obteniendo mapping {}", mappingFilePath); throw new ResourceNotFoundException(e); } } } src/main/java/es/redmic/es/common/utils/ElasticSearchUtils.java +18 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,9 @@ package es.redmic.es.common.utils; */ import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; Loading @@ -28,6 +31,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.apache.commons.io.IOUtils; import org.apache.lucene.search.join.ScoreMode; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.MultiGetItemResponse; Loading @@ -51,11 +55,13 @@ import org.elasticsearch.search.fetch.subphase.highlight.HighlightField; import org.elasticsearch.search.sort.SortBuilder; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import es.redmic.exception.custom.ResourceNotFoundException; import es.redmic.exception.elasticsearch.ESParseException; import es.redmic.models.es.common.query.dto.AggsPropertiesDTO; import es.redmic.models.es.common.query.dto.SortDTO; Loading Loading @@ -279,4 +285,16 @@ public class ElasticSearchUtils { return suggestFields; } public static String getScriptFile(String mappingFilePath) { try { InputStream resource = new ClassPathResource(mappingFilePath).getInputStream(); return IOUtils.toString(resource, Charset.forName(StandardCharsets.UTF_8.name())); } catch (IOException e) { e.printStackTrace(); throw new ResourceNotFoundException(e); } } } Loading
src/main/java/es/redmic/es/common/repository/RBaseESRepository.java +6 −17 Original line number Diff line number Diff line Loading @@ -97,6 +97,10 @@ public abstract class RBaseESRepository<TModel extends BaseES<?>> implements IRB protected static final Logger LOGGER = LoggerFactory.getLogger(RBaseESRepository.class); private static final String UPDATE_NESTED_PROPERTY_SCRIPT_PATH = "/scripts/update-nested-property.txt"; private static final String UPDATE_PROPERTY_SCRIPT_PATH = "/scripts/update-property.txt"; @Value("${redmic.elasticsearch.check.mappings}") private boolean checkMappings; Loading Loading @@ -957,13 +961,11 @@ public abstract class RBaseESRepository<TModel extends BaseES<?>> implements IRB protected String getUpdatePropertyScript() { // TODO: return inline script return ""; return ElasticSearchUtils.getScriptFile(UPDATE_PROPERTY_SCRIPT_PATH); } protected String getUpdateNestedPropertyScript() { // TODO: return inline script return ""; return ElasticSearchUtils.getScriptFile(UPDATE_NESTED_PROPERTY_SCRIPT_PATH); } protected abstract String[] getDefaultSearchFields(); Loading @@ -990,17 +992,4 @@ public abstract class RBaseESRepository<TModel extends BaseES<?>> implements IRB public String getType() { return TYPE; } protected String getScriptFile(String mappingFilePath) { try { InputStream resource = new ClassPathResource(mappingFilePath).getInputStream(); return IOUtils.toString(resource, Charset.forName(StandardCharsets.UTF_8.name())); } catch (IOException e) { e.printStackTrace(); LOGGER.error("Error obteniendo mapping {}", mappingFilePath); throw new ResourceNotFoundException(e); } } }
src/main/java/es/redmic/es/common/utils/ElasticSearchUtils.java +18 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,9 @@ package es.redmic.es.common.utils; */ import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; Loading @@ -28,6 +31,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.apache.commons.io.IOUtils; import org.apache.lucene.search.join.ScoreMode; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.MultiGetItemResponse; Loading @@ -51,11 +55,13 @@ import org.elasticsearch.search.fetch.subphase.highlight.HighlightField; import org.elasticsearch.search.sort.SortBuilder; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import es.redmic.exception.custom.ResourceNotFoundException; import es.redmic.exception.elasticsearch.ESParseException; import es.redmic.models.es.common.query.dto.AggsPropertiesDTO; import es.redmic.models.es.common.query.dto.SortDTO; Loading Loading @@ -279,4 +285,16 @@ public class ElasticSearchUtils { return suggestFields; } public static String getScriptFile(String mappingFilePath) { try { InputStream resource = new ClassPathResource(mappingFilePath).getInputStream(); return IOUtils.toString(resource, Charset.forName(StandardCharsets.UTF_8.name())); } catch (IOException e) { e.printStackTrace(); throw new ResourceNotFoundException(e); } } }