diff --git a/web/src/main/webResources/WEB-INF/config.properties b/web/src/main/webResources/WEB-INF/config.properties
index 3f46f22bfd7..9cebd1c4176 100644
--- a/web/src/main/webResources/WEB-INF/config.properties
+++ b/web/src/main/webResources/WEB-INF/config.properties
@@ -13,5 +13,6 @@ usersavedselection.watchlist.recordurl=api/records/{{index:_uuid}}
es.url=${es.url}
es.index.features=${es.index.features}
+es.index.records=${es.index.records}
jms.url=${jms.url}
diff --git a/workers/wfsfeature-harvester/pom.xml b/workers/wfsfeature-harvester/pom.xml
index e52ea549ee2..aa205a1fea0 100644
--- a/workers/wfsfeature-harvester/pom.xml
+++ b/workers/wfsfeature-harvester/pom.xml
@@ -90,6 +90,12 @@
${project.version}
+
+ org.geonetwork-opensource
+ es-core
+ ${project.version}
+
+
${project.groupId}
messaging
@@ -107,22 +113,9 @@
spring-web
-
org.geotools
gt-geojson
-
-
-
- io.searchbox
- jest
-
diff --git a/workers/wfsfeature-harvester/src/main/java/org/fao/geonet/harvester/wfsfeatures/WFSHarvesterApi.java b/workers/wfsfeature-harvester/src/main/java/org/fao/geonet/harvester/wfsfeatures/WFSHarvesterApi.java
index d7748c689d9..76cc3b491a0 100644
--- a/workers/wfsfeature-harvester/src/main/java/org/fao/geonet/harvester/wfsfeatures/WFSHarvesterApi.java
+++ b/workers/wfsfeature-harvester/src/main/java/org/fao/geonet/harvester/wfsfeatures/WFSHarvesterApi.java
@@ -29,9 +29,10 @@
import org.apache.log4j.Logger;
import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.api.API;
+import org.fao.geonet.es.EsClient;
import org.fao.geonet.harvester.wfsfeatures.event.WFSHarvesterEvent;
import org.fao.geonet.harvester.wfsfeatures.model.WFSHarvesterParameter;
-import org.fao.geonet.harvester.wfsfeatures.worker.EsClient;
+import org.fao.geonet.harvester.wfsfeatures.worker.EsWFSFeatureIndexer;
import org.fao.geonet.harvester.wfsfeatures.worker.WFSHarvesterRouteBuilder;
import org.geonetwork.messaging.JMSMessager;
import org.springframework.beans.factory.annotation.Autowired;
@@ -43,7 +44,6 @@
import java.util.HashMap;
-import static org.fao.geonet.harvester.wfsfeatures.worker.EsWFSFeatureIndexer.deleteFeatures;
/**
* Created by fgravin on 10/29/15.
@@ -98,8 +98,10 @@ public JSONObject deleteWfs(
@RequestParam
String typeName) throws Exception {
-
- deleteFeatures(serviceUrl, typeName, Logger.getLogger(WFSHarvesterRouteBuilder.LOGGER_NAME), client);
+ EsWFSFeatureIndexer indexer = ApplicationContextHolder.get().getBean(EsWFSFeatureIndexer.class);
+ indexer.deleteFeatures(serviceUrl, typeName,
+ Logger.getLogger(WFSHarvesterRouteBuilder.LOGGER_NAME),
+ client);
// TODO: Check user is authenticated ?
JSONObject result = new JSONObject();
diff --git a/workers/wfsfeature-harvester/src/main/java/org/fao/geonet/harvester/wfsfeatures/worker/EsWFSFeatureIndexer.java b/workers/wfsfeature-harvester/src/main/java/org/fao/geonet/harvester/wfsfeatures/worker/EsWFSFeatureIndexer.java
index 22a7581c533..43735e54166 100644
--- a/workers/wfsfeature-harvester/src/main/java/org/fao/geonet/harvester/wfsfeatures/worker/EsWFSFeatureIndexer.java
+++ b/workers/wfsfeature-harvester/src/main/java/org/fao/geonet/harvester/wfsfeatures/worker/EsWFSFeatureIndexer.java
@@ -37,6 +37,7 @@
import org.apache.camel.Exchange;
import org.apache.jcs.access.exception.InvalidArgumentException;
import org.apache.log4j.Logger;
+import org.fao.geonet.es.EsClient;
import org.fao.geonet.harvester.wfsfeatures.model.WFSHarvesterParameter;
import org.geotools.data.FeatureSource;
import org.geotools.data.Query;
@@ -56,6 +57,7 @@
import org.opengis.metadata.extent.GeographicExtent;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
@@ -64,7 +66,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.StringTokenizer;
//import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -75,6 +76,9 @@ public class EsWFSFeatureIndexer {
public static final String TREE_FIELD_SUFFIX = "_tree";
public static final String FEATURE_FIELD_PREFIX = "ft_";
+ @Value("es.index.features")
+ private String index = "features";
+
@Autowired
private EsClient client;
@@ -172,16 +176,16 @@ public void deleteFeatures(Exchange exchange) {
deleteFeatures(url, typeName, logger, client);
}
- public static void deleteFeatures(String url, String typeName, Logger logger,
+ public void deleteFeatures(String url, String typeName, Logger logger,
EsClient client) {
logger.info(String.format(
"Deleting features previously index from service '%s' and feature type '%s' in '%s'",
- url, typeName, client.getCollection()));
+ url, typeName, index));
try {
ZonedDateTime startTime = ZonedDateTime.now();
String msg = client.deleteByQuery(
- client.getCollection(),
+ index,
String.format(
"+featureTypeId:\\\"%s#%s\\\"", url, typeName)
);
@@ -191,7 +195,7 @@ public static void deleteFeatures(String url, String typeName, Logger logger,
startTime = ZonedDateTime.now();
msg = client.deleteByQuery(
- client.getCollection(),
+ index,
String.format(
"+id:\\\"%s#%s\\\"", url, typeName)
);
@@ -202,18 +206,18 @@ public static void deleteFeatures(String url, String typeName, Logger logger,
e.printStackTrace();
logger.error(String.format(
"Error connecting to ES at '%s'. Error is %s.",
- client.getCollection(), e.getMessage()));
+ index, e.getMessage()));
}
}
private void saveHarvesterReport(WFSHarvesterExchangeState state) {
Map
report = state.getHarvesterReport();
- Index index = new Index.Builder(report)
- .index(client.getCollection())
- .type(client.getCollection())
+ Index search = new Index.Builder(report)
+ .index(index)
+ .type(index)
.id(report.get("id").toString()).build();
try {
- DocumentResult response = client.getClient().execute(index);
+ DocumentResult response = client.getClient().execute(search);
logger.info(String.format(
"Report saved for %s. Error is '%s'.",
state.getParameters().getTypeName(),
@@ -445,7 +449,7 @@ public void indexFeatures(Exchange exchange) throws Exception {
typeName, nbOfFeatures));
}
try {
- client.bulkRequest(client.getCollection(),
+ client.bulkRequest(index,
docCollection);
} catch (Exception ex) {
state.getHarvesterReport().put("error_ss", String.format(
@@ -472,7 +476,7 @@ public void indexFeatures(Exchange exchange) throws Exception {
typeName, nbOfFeatures));
}
try {
- client.bulkRequest(client.getCollection(),
+ client.bulkRequest(index,
docCollection);
} catch (Exception ex) {
state.getHarvesterReport().put("error_ss", String.format(
@@ -507,4 +511,8 @@ public void indexFeatures(Exchange exchange) throws Exception {
saveHarvesterReport(state);
}
}
+
+ public void setIndex(String index) {
+ this.index = index;
+ }
}
diff --git a/workers/wfsfeature-harvester/src/main/resources/config-spring-geonetwork.xml b/workers/wfsfeature-harvester/src/main/resources/config-spring-geonetwork.xml
index 539bcba4079..3b05db48419 100644
--- a/workers/wfsfeature-harvester/src/main/resources/config-spring-geonetwork.xml
+++ b/workers/wfsfeature-harvester/src/main/resources/config-spring-geonetwork.xml
@@ -48,10 +48,7 @@
-
-
-
+ class="org.fao.geonet.es.EsClient"/>