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 f66e5e8e91d..1c352b3b2ac 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 @@ -26,6 +26,7 @@ import co.elastic.clients.elasticsearch._types.SortOptions; import co.elastic.clients.elasticsearch.core.SearchResponse; import co.elastic.clients.elasticsearch.core.search.Hit; +import co.elastic.clients.elasticsearch.core.search.TotalHits; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import jeeves.server.context.ServiceContext; @@ -458,8 +459,9 @@ public Element search(ServiceContext context, int startPos, int maxRecords, SearchResponse result = searchManager.query(esJsonQuery, new HashSet<>(), startPos-1, maxRecords, sort); List hits = result.hits().hits(); - - long numMatches = result.hits().hits().size(); + + TotalHits total = result.hits().total(); + long numMatches = total != null ? total.value() : 0; if (numMatches != 0 && startPos > numMatches) { throw new InvalidParameterValueEx("startPosition", String.format(