diff --git a/csw-server/src/main/java/org/fao/geonet/kernel/csw/services/getrecords/SearchController.java b/csw-server/src/main/java/org/fao/geonet/kernel/csw/services/getrecords/SearchController.java index 99ac7c50b3..be4a62fb5f 100644 --- a/csw-server/src/main/java/org/fao/geonet/kernel/csw/services/getrecords/SearchController.java +++ b/csw-server/src/main/java/org/fao/geonet/kernel/csw/services/getrecords/SearchController.java @@ -449,7 +449,7 @@ public Element search(ServiceContext context, int startPos, int maxRecords, try { String filterQueryString = esFilterBuilder.build(context, "metadata", false, node); - String jsonQuery = String.format(elasticSearchQuery, filterQueryString); + String jsonQuery = StringUtils.replace(elasticSearchQuery, "{@}", filterQueryString); ObjectMapper objectMapper = new ObjectMapper(); esJsonQuery = objectMapper.readTree(jsonQuery); diff --git a/csw-server/src/main/java/org/fao/geonet/kernel/csw/services/getrecords/es/CswFilter2Es.java b/csw-server/src/main/java/org/fao/geonet/kernel/csw/services/getrecords/es/CswFilter2Es.java index a760a23e7d..754ad2eee9 100644 --- a/csw-server/src/main/java/org/fao/geonet/kernel/csw/services/getrecords/es/CswFilter2Es.java +++ b/csw-server/src/main/java/org/fao/geonet/kernel/csw/services/getrecords/es/CswFilter2Es.java @@ -67,7 +67,7 @@ public class CswFilter2Es extends AbstractFilterVisitor { " \"must\": [\n" + " %s\n" + " ]\n" + - " ,\"filter\":{\"query_string\":{\"query\":\"%s\"}}}"; //, "minimum_should_match" : 1 + " ,\"filter\":{\"query_string\":{\"query\":\"{@}\"}}}"; //, "minimum_should_match" : 1 private static final String TEMPLATE_OR = " {\"bool\": {\n" + " \"should\": [\n" + " %s\n" + @@ -77,7 +77,7 @@ public class CswFilter2Es extends AbstractFilterVisitor { " \"should\": [\n" + " %s\n" + " ]\n" + - " ,\"filter\":{\"query_string\":{\"query\":\"%s\"}}, \"minimum_should_match\" : 1}"; + " ,\"filter\":{\"query_string\":{\"query\":\"{@}\"}}, \"minimum_should_match\" : 1}"; private static final String TEMPLATE_MATCH = "{\"query_string\": {\n" + " \"fields\": [\"%s\"],\n" + " \"query\": \"%s\"\n" + diff --git a/csw-server/src/test/java/org/fao/geonet/kernel/csw/services/getrecords/es/CswFilter2EsTest.java b/csw-server/src/test/java/org/fao/geonet/kernel/csw/services/getrecords/es/CswFilter2EsTest.java index a67a5031a5..b89996e6cc 100644 --- a/csw-server/src/test/java/org/fao/geonet/kernel/csw/services/getrecords/es/CswFilter2EsTest.java +++ b/csw-server/src/test/java/org/fao/geonet/kernel/csw/services/getrecords/es/CswFilter2EsTest.java @@ -93,7 +93,7 @@ private static ObjectNode queryStringPart(String field, String queryString) { fieldValues.add(field); query.set("fields", fieldValues); } - query.put("query", queryString == null ? "%s" : queryString); + query.put("query", queryString == null ? "{@}" : queryString); queryStringNode.set("query_string", query);