Repository: gisaia/ARLAS-server (language: python)

Issue:
[fetch_hits][raw_geometries] make sort on chosen fields optional
- For now, even if no sort is specified on the fields of `fetch_hits` or `raw_geometries`, a desc sort is still applied on the given fields and that should be removed


Discussion / hints:

Fix patch:
diff --git a/arlas-core/src/main/java/io/arlas/server/core/impl/elastic/services/ElasticExploreService.java b/arlas-core/src/main/java/io/arlas/server/core/impl/elastic/services/ElasticExploreService.java
index e41abf21e..be52026c0 100644
--- a/arlas-core/src/main/java/io/arlas/server/core/impl/elastic/services/ElasticExploreService.java
+++ b/arlas-core/src/main/java/io/arlas/server/core/impl/elastic/services/ElasticExploreService.java
@@ -445,15 +445,30 @@ private AggregationResponse formatAggregationResult(MultiBucketsAggregation aggr
                         }
                         element.geometries.add(returnedGeometry);
                     } else if (subAggregation.getName().startsWith(RAW_GEOMETRY_SUFFIX)) {
-                        String sort = subAggregation.getName().substring(RAW_GEOMETRY_SUFFIX.length());
+                        boolean includeFetchHits = subAggregation.getName().contains(FETCH_HITS_AGG);
+                        String sort = !includeFetchHits ? subAggregation.getName().substring(RAW_GEOMETRY_SUFFIX.length()) :
+                                subAggregation.getName().substring(RAW_GEOMETRY_SUFFIX.length()+FETCH_HITS_AGG.length()) ;
                         subAggregationResponse = null;
                         long nbHits = ((TopHits) subAggregation).getHits().getTotalHits().value;
                         if (nbHits > 0) {
                             SearchHit[] hits = ((TopHits) subAggregation).getHits().getHits();
+                            if(includeFetchHits){
+                                element.hits = Optional.ofNullable(hits)
+                                        .map(Arrays::asList)
+                                        .map(hitsList -> hitsList.stream()
+                                                .map(SearchHit::getSourceAsMap)
+                                                .collect(Collectors.toList()))
+                                        .orElse(new ArrayList());
+                            }
                             for (SearchHit hit: hits) {
                                 Map source = hit.getSourceAsMap();
                                 if (rawGeometries != null) {
-                                    List<String> geometries = rawGeometries.stream().filter(rg -> rg.sort.equals(sort)).map(rg -> rg.geometry).collect(Collectors.toList());
+                                    List<String> geometries;
+                                    if(includeFetchHits){
+                                        geometries = rawGeometries.stream().filter(rg -> rg.signedSort.equals(sort)).map(rg -> rg.geometry).collect(Collectors.toList());
+                                    }else {
+                                         geometries = rawGeometries.stream().filter(rg -> rg.sort.equals(sort)).map(rg -> rg.geometry).collect(Collectors.toList());
+                                    }
                                     geometries.forEach(g -> {
                                         GeoJsonObject geometryGeoJson;
                                         try {
diff --git a/arlas-core/src/main/java/io/arlas/server/core/impl/elastic/services/ElasticFluidSearch.java b/arlas-core/src/main/java/io/arlas/server/core/impl/elastic/services/ElasticFluidSearch.java
index 68d66f95c..f51bf7d5a 100644
--- a/arlas-core/src/main/java/io/arlas/server/core/impl/elastic/services/ElasticFluidSearch.java
+++ b/arlas-core/src/main/java/io/arlas/server/core/impl/elastic/services/ElasticFluidSearch.java
@@ -60,6 +60,7 @@
 
 import java.io.IOException;
 import java.util.*;
+import java.util.stream.Collectors;
 
 import static io.arlas.server.core.utils.CheckParams.GEO_AGGREGATION_TYPE_ENUMS;
 
@@ -570,9 +571,9 @@ private DateHistogramAggregationBuilder buildDateHistogramAggregation(Aggregatio
         }
         //get the field, format, collect_field, collect_fct, order, on
         dateHistogramAggregationBuilder = (DateHistogramAggregationBuilder) setAggregationParameters(aggregationModel, dateHistogramAggregationBuilder);
-        dateHistogramAggregationBuilder = (DateHistogramAggregationBuilder) setHitsToFetch(aggregationModel, dateHistogramAggregationBuilder);
         dateHistogramAggregationBuilder = (DateHistogramAggregationBuilder) setAggregatedGeometries(aggregationModel, dateHistogramAggregationBuilder);
-        dateHistogramAggregationBuilder = (DateHistogramAggregationBuilder) setRawGeometries(aggregationModel, dateHistogramAggregationBuilder);
+        dateHistogramAggregationBuilder = (DateHistogramAggregationBuilder) setRawGeometriesAndFetch(aggregationModel, dateHistogramAggregationBuilder);
+
         return dateHistogramAggregationBuilder;
     }
 
@@ -585,8 +586,8 @@ private GeoGridAggregationBuilder buildGeohashAggregation(Aggregation aggregatio
         //get the field, format, collect_field, collect_fct, order, on
         geoHashAggregationBuilder = (GeoGridAggregationBuilder) setAggregationParameters(aggregationModel, geoHashAggregationBuilder);
         geoHashAggregationBuilder = (GeoGridAggregationBuilder) setAggregatedGeometries(aggregationModel, geoHashAggregationBuilder);
-        geoHashAggregationBuilder = (GeoGridAggregationBuilder) setRawGeometries(aggregationModel, geoHashAggregationBuilder);
-        geoHashAggregationBuilder = (GeoGridAggregationBuilder) setHitsToFetch(aggregationModel, geoHashAggregationBuilder);
+        geoHashAggregationBuilder = (GeoGridAggregationBuilder) setRawGeometriesAndFetch(aggregationModel, geoHashAggregationBuilder);
+
         return geoHashAggregationBuilder;
     }
 
@@ -599,8 +600,8 @@ private GeoGridAggregationBuilder buildGeotileAggregation(Aggregation aggregatio
         //get the field, format, collect_field, collect_fct, order, on
         geoTileAggregationBuilder = (GeoGridAggregationBuilder) setAggregationParameters(aggregationModel, geoTileAggregationBuilder);
         geoTileAggregationBuilder = (GeoGridAggregationBuilder) setAggregatedGeometries(aggregationModel, geoTileAggregationBuilder);
-        geoTileAggregationBuilder = (GeoGridAggregationBuilder) setRawGeometries(aggregationModel, geoTileAggregationBuilder);
-        geoTileAggregationBuilder = (GeoGridAggregationBuilder) setHitsToFetch(aggregationModel, geoTileAggregationBuilder);
+        geoTileAggregationBuilder = (GeoGridAggregationBuilder) setRawGeometriesAndFetch(aggregationModel, geoTileAggregationBuilder);
+
         return geoTileAggregationBuilder;
     }
 
@@ -614,8 +615,8 @@ private TermsAggregationBuilder buildH3Aggregation(Aggregation aggregationModel)
         //get the field, format, collect_field, collect_fct, order, on
         termsAggregationBuilder = (TermsAggregationBuilder) setAggregationParameters(aggregationModel, termsAggregationBuilder);
         termsAggregationBuilder = (TermsAggregationBuilder) setAggregatedGeometries(aggregationModel, termsAggregationBuilder);
-        termsAggregationBuilder = (TermsAggregationBuilder) setRawGeometries(aggregationModel, termsAggregationBuilder);
-        termsAggregationBuilder = (TermsAggregationBuilder) setHitsToFetch(aggregationModel, termsAggregationBuilder);
+        termsAggregationBuilder = (TermsAggregationBuilder) setRawGeometriesAndFetch(aggregationModel, termsAggregationBuilder);
+
         if (!StringUtil.isNullOrEmpty(aggregationModel.include)) {
             String[] includeList = aggregationModel.include.split(",");
             IncludeExclude includeExclude;
@@ -635,9 +636,8 @@ private HistogramAggregationBuilder buildHistogramAggregation(Aggregation aggreg
         histogramAggregationBuilder = histogramAggregationBuilder.interval((Double)aggregationModel.interval.value);
         //get the field, format, collect_field, collect_fct, order, on
         histogramAggregationBuilder = (HistogramAggregationBuilder) setAggregationParameters(aggregationModel, histogramAggregationBuilder);
-        histogramAggregationBuilder = (HistogramAggregationBuilder) setHitsToFetch(aggregationModel, histogramAggregationBuilder);
         histogramAggregationBuilder = (HistogramAggregationBuilder) setAggregatedGeometries(aggregationModel, histogramAggregationBuilder);
-        histogramAggregationBuilder = (HistogramAggregationBuilder) setRawGeometries(aggregationModel, histogramAggregationBuilder);
+        histogramAggregationBuilder = (HistogramAggregationBuilder) setRawGeometriesAndFetch(aggregationModel, histogramAggregationBuilder);
         return histogramAggregationBuilder;
     }
 
@@ -647,8 +647,7 @@ private TermsAggregationBuilder buildTermsAggregation(Aggregation aggregationMod
         //get the field, format, collect_field, collect_fct, order, on
         termsAggregationBuilder = (TermsAggregationBuilder) setAggregationParameters(aggregationModel, termsAggregationBuilder);
         termsAggregationBuilder = (TermsAggregationBuilder) setAggregatedGeometries(aggregationModel, termsAggregationBuilder);
-        termsAggregationBuilder = (TermsAggregationBuilder) setRawGeometries(aggregationModel, termsAggregationBuilder);
-        termsAggregationBuilder = (TermsAggregationBuilder) setHitsToFetch(aggregationModel, termsAggregationBuilder);
+        termsAggregationBuilder = (TermsAggregationBuilder) setRawGeometriesAndFetch(aggregationModel, termsAggregationBuilder);
         if (!StringUtil.isNullOrEmpty(aggregationModel.include)) {
             String[] includeList = aggregationModel.include.split(",");
             IncludeExclude includeExclude;
@@ -759,6 +758,69 @@ private ValuesSourceAggregationBuilder setAggregatedGeometries(Aggregation aggre
         return aggregationBuilder;
     }
 
+    private ValuesSourceAggregationBuilder setRawGeometriesAndFetch(Aggregation aggregationModel, ValuesSourceAggregationBuilder aggregationBuilder) throws ArlasException {
+        if(aggregationModel.rawGeometries != null && aggregationModel.fetchHits != null){
+            Integer fetchSize = Optional.ofNullable(aggregationModel.fetchHits.size).orElse(1);
+            List<String> signedFetchIncludes = new ArrayList<>();
+            if (aggregationModel.fetchHits.include != null) {
+                for (String field : aggregationModel.fetchHits.include) {
+                    String unsignedField = (field.startsWith("+") || field.startsWith("-")) ? field.substring(1) : field;
+                    ElasticTool.checkAliasMappingFields(client, collectionReference.params.indexName, unsignedField);
+                    if((field.startsWith("+") || field.startsWith("-"))){
+                        signedFetchIncludes.add(field);
+                    }
+                }
+            }
+            List<RawGeometry> mergeableRS = new ArrayList<>();
+            aggregationModel.rawGeometries.forEach(rg -> {
+                List<String>  signedRawGeometriesIncludes = Arrays.stream(rg.sort.split(",")).filter(field -> (field.startsWith("+") || field.startsWith("-"))).collect(Collectors.toList());
+                if(String.join(",", signedRawGeometriesIncludes).equals(String.join(",", signedFetchIncludes))){
+                    rg.setSignedSort(String.join(",", signedFetchIncludes));
+                    rg.setInclude(aggregationModel.fetchHits.include);
+                    mergeableRS.add(rg);
+                }
+            });
+            if(mergeableRS.isEmpty() || fetchSize != 1){
+                aggregationBuilder = this.setRawGeometries(aggregationModel,aggregationBuilder);
+                aggregationBuilder = this.setHitsToFetch(aggregationModel,aggregationBuilder);
+                return aggregationBuilder;
+            }else{
+                Map<String, Set<String>> rgs = new HashMap<>();
+                mergeableRS.forEach(rg -> {
+                    Set<String> geos = rgs.get(rg.signedSort);
+                    if (geos == null) geos = new HashSet<>();
+                    geos.add(rg.geometry);
+                    geos.addAll(rg.include);
+                    rgs.put(rg.signedSort, geos);
+                });
+                for (String sort: rgs.keySet()) {
+                    String[] includes = rgs.get(sort).stream().toArray(String[]::new);
+                    TopHitsAggregationBuilder topHitsAggregationBuilder = AggregationBuilders.topHits(RAW_GEOMETRY_SUFFIX + FETCH_HITS_AGG + sort).size(1).fetchSource(includes, null);
+                    for (String field : sort.split(",")) {
+                        String unsignedField = (field.startsWith("+") || field.startsWith("-")) ? field.substring(1) : field;
+                        if (field.startsWith("+")) {
+                            ElasticTool.checkAliasMappingFields(client, collectionReference.params.indexName, unsignedField);
+                            topHitsAggregationBuilder.sort(unsignedField, SortOrder.ASC);
+                        } else if(field.startsWith("-")) {
+                            ElasticTool.checkAliasMappingFields(client, collectionReference.params.indexName, unsignedField);
+                            topHitsAggregationBuilder.sort(unsignedField, SortOrder.DESC);
+                        }
+                    }
+                    aggregationBuilder.subAggregation(topHitsAggregationBuilder);
+                }
+                return  aggregationBuilder;
+            }
+        }
+        if(aggregationModel.rawGeometries != null && aggregationModel.fetchHits == null){
+            return this.setRawGeometries(aggregationModel,aggregationBuilder);
+        }
+        if(aggregationModel.rawGeometries == null && aggregationModel.fetchHits != null){
+            return this.setHitsToFetch(aggregationModel,aggregationBuilder);
+        }
+        //If no rawGeometries and no fetchHits
+        return  aggregationBuilder;
+    }
+
     private ValuesSourceAggregationBuilder setRawGeometries(Aggregation aggregationModel, ValuesSourceAggregationBuilder aggregationBuilder) throws ArlasException {
         if (aggregationModel.rawGeometries != null) {
             Map<String, Set<String>> rgs = new HashMap<>();
@@ -774,15 +836,16 @@ private ValuesSourceAggregationBuilder setRawGeometries(Aggregation aggregationM
                 for (String field : sort.split(",")) {
                     String unsignedField = (field.startsWith("+") || field.startsWith("-")) ? field.substring(1) : field;
                     ElasticTool.checkAliasMappingFields(client, collectionReference.params.indexName, unsignedField);
-                    if (field.startsWith("+") || !field.startsWith("-")) {
+                    if (field.startsWith("+")) {
+                        ElasticTool.checkAliasMappingFields(client, collectionReference.params.indexName, unsignedField);
                         topHitsAggregationBuilder.sort(unsignedField, SortOrder.ASC);
-                    } else {
+                    } else if(field.startsWith("-")) {
+                        ElasticTool.checkAliasMappingFields(client, collectionReference.params.indexName, unsignedField);
                         topHitsAggregationBuilder.sort(unsignedField, SortOrder.DESC);
                     }
                 }
                 aggregationBuilder.subAggregation(topHitsAggregationBuilder);
             }
-
         }
         return aggregationBuilder;
     }
@@ -796,20 +859,19 @@ private ValuesSourceAggregationBuilder setHitsToFetch(Aggregation aggregationMod
             if (aggregationModel.fetchHits.include != null) {
                 for (String field : aggregationModel.fetchHits.include) {
                     String unsignedField = (field.startsWith("+") || field.startsWith("-")) ? field.substring(1) : field;
-                    ElasticTool.checkAliasMappingFields(client, collectionReference.params.indexName, unsignedField);
-                    includes.add(unsignedField);
-                    /** For geo-fields, we don't sort them. Sorting geo-fields need to be according a given point to calculate a geo-distance
-                     * which is not supported in the syntax of fetch_hits*/
-                    if (CollectionReferenceManager.getInstance().getType(collectionReference, unsignedField, false) != FieldType.GEO_POINT && CollectionReferenceManager.getInstance().getType(collectionReference, unsignedField, false) != FieldType.GEO_SHAPE) {
-                        if (field.startsWith("+") || !field.startsWith("-")) {
-                            topHitsAggregationBuilder.sort(unsignedField, SortOrder.ASC);
-                        } else {
-                            topHitsAggregationBuilder.sort(unsignedField, SortOrder.DESC);
+                    if(!field.isEmpty()){
+                        ElasticTool.checkAliasMappingFields(client, collectionReference.params.indexName, unsignedField);
+                        includes.add(unsignedField);
+                        /** For geo-fields, we don't sort them. Sorting geo-fields need to be according a given point to calculate a geo-distance
+                         * which is not supported in the syntax of fetch_hits*/
+                        if (CollectionReferenceManager.getInstance().getType(collectionReference, unsignedField, false) != FieldType.GEO_POINT && CollectionReferenceManager.getInstance().getType(collectionReference, unsignedField, false) != FieldType.GEO_SHAPE) {
+                            if (field.startsWith("+")) {
+                                topHitsAggregationBuilder.sort(unsignedField, SortOrder.ASC);
+                            } else if(field.startsWith("-")) {
+                                topHitsAggregationBuilder.sort(unsignedField, SortOrder.DESC);
+                            }
                         }
                     }
-
-
-
                 }
                 String[] hitsToInclude = includes.toArray(new String[includes.size()]);
                 topHitsAggregationBuilder.fetchSource(hitsToInclude, null);
diff --git a/arlas-core/src/main/java/io/arlas/server/core/model/request/RawGeometry.java b/arlas-core/src/main/java/io/arlas/server/core/model/request/RawGeometry.java
index 11e545c1b..f7bf2950a 100644
--- a/arlas-core/src/main/java/io/arlas/server/core/model/request/RawGeometry.java
+++ b/arlas-core/src/main/java/io/arlas/server/core/model/request/RawGeometry.java
@@ -19,9 +19,13 @@
 
 package io.arlas.server.core.model.request;
 
+import java.util.List;
+
 public class RawGeometry {
     public String geometry;
     public String sort;
+    public String signedSort;
+    public List<String> include;
 
     public RawGeometry() {
     }
@@ -34,4 +38,20 @@ public RawGeometry(String geometry, String sort) {
         this.geometry = geometry;
         this.sort = sort;
     }
+
+    public String getSignedSort() {
+        return signedSort;
+    }
+
+    public void setSignedSort(String signedSort) {
+        this.signedSort = signedSort;
+    }
+
+    public List<String> getInclude() {
+        return include;
+    }
+
+    public void setInclude(List<String> include) {
+        this.include = include;
+    }
 }
diff --git a/arlas-rest/src/main/java/io/arlas/server/rest/explore/aggregate/GeoAggregateRESTService.java b/arlas-rest/src/main/java/io/arlas/server/rest/explore/aggregate/GeoAggregateRESTService.java
index f25a95b9e..6201cc6c7 100644
--- a/arlas-rest/src/main/java/io/arlas/server/rest/explore/aggregate/GeoAggregateRESTService.java
+++ b/arlas-rest/src/main/java/io/arlas/server/rest/explore/aggregate/GeoAggregateRESTService.java
@@ -781,16 +781,28 @@ private FeatureCollection toGeoJson(AggregationResponse aggregationResponse, Agg
                        }
                        if (flat) {
                            properties.putAll(exploreService.flat(element, new MapExplorer.ReduceArrayOnKey(ArlasServerConfiguration.FLATTEN_CHAR), s -> (!"elements".equals(s))));
+                           // To remove the geometry from the properties when we make a raw geom with include
+                           String keyToRemove = "";
+                           for (String key: properties.keySet()) {
+                               List<String> kElements =  Arrays.asList(key.split(ArlasServerConfiguration.FLATTEN_CHAR));
+                               if(kElements.size()>1 && kElements.get(0).equals("hits") ){
+                                   if(String.join(".", kElements.subList(2,kElements.size())).equals(g.reference)){
+                                       keyToRemove=key;
+                                   }
+                               }
+                           }
+                           properties.remove(keyToRemove);
                        }else{
                            properties.put("elements", element.elements);
                            properties.put("metrics", element.metrics);
                            if (element.hits != null) {
-                               properties.put("hits", element.hits);
+                               properties.put("hits", element.hits.stream());
                            }
                        }
                        feature.setProperties(properties);
                        feature.setProperty(FEATURE_TYPE_KEY, FEATURE_TYPE_VALUE);
                        feature.setProperty(GEOMETRY_REFERENCE, g.reference);
+
                        String aggregationGeometryType = g.isRaw ? AggregationGeometryEnum.RAW.value() : AggregationGeometryEnum.AGGREGATED.value();
                        feature.setProperty(GEOMETRY_TYPE, aggregationGeometryType);
                        if (g.isRaw) {


Test patch:
diff --git a/arlas-tests/src/test/java/io/arlas/server/tests/rest/explore/AbstractAggregatedTest.java b/arlas-tests/src/test/java/io/arlas/server/tests/rest/explore/AbstractAggregatedTest.java
index 9ff27d50c..906e429bb 100644
--- a/arlas-tests/src/test/java/io/arlas/server/tests/rest/explore/AbstractAggregatedTest.java
+++ b/arlas-tests/src/test/java/io/arlas/server/tests/rest/explore/AbstractAggregatedTest.java
@@ -534,9 +534,9 @@ public void testDateHistogramAggregate() throws Exception {
         handleMatchingAggregateWithGeometry(post(aggregationRequest), 10, 1, 104, -171F, -81F, 171F, 81F);
         handleMatchingAggregateWithGeometry(get("datehistogram:interval-1minute:raw_geometries-geo_params.geometry(-params.startdate)"), 10, 1, 104, -171F, -81F, 171F, 81F);
 
-        aggregationRequest.aggregations.get(0).rawGeometries = Arrays.asList(new RawGeometry("geo_params.geometry", "params.age"));
+        aggregationRequest.aggregations.get(0).rawGeometries = Arrays.asList(new RawGeometry("geo_params.geometry", "+params.age"));
         handleMatchingAggregateWithGeometry(post(aggregationRequest), 10, 1, 104, -171F, -71F, 171F, 81F);
-        handleMatchingAggregateWithGeometry(get("datehistogram:interval-1minute:raw_geometries-geo_params.geometry(params.age)"), 10, 1, 104, -171F, -71F, 171F, 81F);
+        handleMatchingAggregateWithGeometry(get("datehistogram:interval-1minute:raw_geometries-geo_params.geometry(+params.age)"), 10, 1, 104, -171F, -71F, 171F, 81F);
 
         aggregationRequest.aggregations.get(0).rawGeometries = Arrays.asList(new RawGeometry("geo_params.geometry", "-params.age"));
         handleMatchingAggregateWithGeometry(post(aggregationRequest), 10, 1, 104, -171F, -81F, 171F, 81F);
@@ -712,9 +712,9 @@ public void testHistogramAggregate() throws Exception {
         handleMatchingAggregateWithGeometry(post(aggregationRequest), 10, 1, 104, -171F, -81F, 171F, 81F);
         handleMatchingAggregateWithGeometry(get("histogram:params.startdate:interval-60000:raw_geometries-geo_params.geometry(-params.startdate)"), 10, 1, 104, -171F, -81F, 171F, 81F);
 
-        aggregationRequest.aggregations.get(0).rawGeometries = Arrays.asList(new RawGeometry("geo_params.geometry", "params.age"));
+        aggregationRequest.aggregations.get(0).rawGeometries = Arrays.asList(new RawGeometry("geo_params.geometry", "+params.age"));
         handleMatchingAggregateWithGeometry(post(aggregationRequest), 10, 1, 104, -171F, -71F, 171F, 81F);
-        handleMatchingAggregateWithGeometry(get("histogram:params.startdate:interval-60000:raw_geometries-geo_params.geometry(params.age)"), 10, 1, 104, -171F, -71F, 171F, 81F);
+        handleMatchingAggregateWithGeometry(get("histogram:params.startdate:interval-60000:raw_geometries-geo_params.geometry(+params.age)"), 10, 1, 104, -171F, -71F, 171F, 81F);
 
         aggregationRequest.aggregations.get(0).rawGeometries = Arrays.asList(new RawGeometry("geo_params.geometry", "-params.age"));
         handleMatchingAggregateWithGeometry(post(aggregationRequest), 10, 1, 104, -171F, -81F, 171F, 81F);
@@ -934,9 +934,11 @@ public void testTermAggregate() throws Exception {
         handleMatchingAggregateWithGeometry(get("term:params.job:aggregated_geometries-bbox"), DataSetTool.jobs.length - 1, 58, 64, -170.1F, -80.1F, 170F, 80F);
 
         aggregationRequest.aggregations.get(0).aggregatedGeometries = null;
-        aggregationRequest.aggregations.get(0).rawGeometries = Arrays.asList(new RawGeometry("geo_params.geometry"));
+        // We need to add a sort in this test to have a constant response between aliases and not aliases
+        // Fetch without sort dont give the same result with alias and not alias
+        aggregationRequest.aggregations.get(0).rawGeometries = Arrays.asList(new RawGeometry("geo_params.geometry","+params.startdate"));
         handleMatchingAggregateWithGeometry(post(aggregationRequest), DataSetTool.jobs.length - 1, 58, 64, -171F, -81F, -159F, 1F);
-        handleMatchingAggregateWithGeometry(get("term:params.job:raw_geometries-geo_params.geometry"), DataSetTool.jobs.length - 1, 58, 64, -171F, -81F, -159F, 1F);
+        handleMatchingAggregateWithGeometry(get("term:params.job:raw_geometries-geo_params.geometry(+params.startdate)"), DataSetTool.jobs.length - 1, 58, 64, -171F, -81F, -159F, 1F);
 
         aggregationRequest.aggregations.get(0).rawGeometries = Arrays.asList(new RawGeometry("geo_params.geometry", "-params.startdate"));
         handleMatchingAggregateWithGeometry(post(aggregationRequest), DataSetTool.jobs.length - 1, 58, 64, 79F, 79F, 171F, 81F);