diff --git a/modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/controller/ItemApiController.java b/modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/controller/ItemApiController.java index 505bf55f..57cea862 100644 --- a/modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/controller/ItemApiController.java +++ b/modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/controller/ItemApiController.java @@ -575,6 +575,7 @@ private ResponseEntity collectionsCollectionIdItemsGetAsHtml( String collectionFilter = collectionService.retrieveCollectionFilter(source, false); String query = recordsEsQueryBuilder .buildQuery(q, externalids, bbox, startindex, limit, collectionFilter, sortby, null); + EsSearchResults results = new EsSearchResults(); try { results = proxy diff --git a/modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/util/RecordsEsQueryBuilder.java b/modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/util/RecordsEsQueryBuilder.java index 81711090..f8a86621 100644 --- a/modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/util/RecordsEsQueryBuilder.java +++ b/modules/services/ogc-api-records/src/main/java/org/fao/geonet/ogcapi/records/util/RecordsEsQueryBuilder.java @@ -14,6 +14,7 @@ import org.elasticsearch.geometry.Rectangle; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.GeoShapeQueryBuilder; +import org.elasticsearch.index.query.Operator; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.builder.SearchSourceBuilder; @@ -141,11 +142,15 @@ public String buildQuery( } } - String filterQueryString = configuration.getQueryFilter(); + String filterQueryString = "(" + configuration.getQueryFilter() + ")"; if (StringUtils.isNotEmpty(collectionFilter)) { - filterQueryString += " " + collectionFilter; + filterQueryString += " (" + collectionFilter + ")"; } - boolQuery.filter(QueryBuilders.queryStringQuery(filterQueryString)); + + var bbQuery = QueryBuilders.queryStringQuery(filterQueryString); + bbQuery.defaultOperator(Operator.AND); + boolQuery.filter(bbQuery); + sourceBuilder.query(boolQuery); sourceBuilder.trackTotalHits(configuration.getTrackTotalHits()); log.debug("OGC API query: {}", sourceBuilder.toString());