forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored the src and test of GeoHashGrid and GeoTileGrid Aggregatio…
…ns on GeoPoint from server folder to geo module.(opensearch-project#4071) (opensearch-project#4072) (opensearch-project#4180) The changes also includes: * Updated Search plugin to provide the interface so that plugins can also register the composite aggregations * Added YAML test for the geo_grid, geo_tile and composite aggregation Signed-off-by: Navneet Verma <[email protected]>
- Loading branch information
Showing
81 changed files
with
1,395 additions
and
763 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/ShardReduceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.geo.search.aggregations.bucket; | ||
|
||
import org.opensearch.action.index.IndexRequestBuilder; | ||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.geo.GeoModulePluginIntegTestCase; | ||
import org.opensearch.geo.search.aggregations.bucket.geogrid.GeoGrid; | ||
import org.opensearch.geo.tests.common.AggregationBuilders; | ||
import org.opensearch.geometry.utils.Geohash; | ||
import org.opensearch.index.query.QueryBuilders; | ||
import org.opensearch.search.aggregations.bucket.histogram.DateHistogramInterval; | ||
import org.opensearch.search.aggregations.bucket.histogram.Histogram; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder; | ||
import static org.opensearch.search.aggregations.AggregationBuilders.dateHistogram; | ||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; | ||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse; | ||
|
||
/** | ||
* Tests making sure that the reduce is propagated to all aggregations in the hierarchy when executing on a single shard | ||
* These tests are based on the date histogram in combination of min_doc_count=0. In order for the date histogram to | ||
* compute empty buckets, its {@code reduce()} method must be called. So by adding the date histogram under other buckets, | ||
* we can make sure that the reduce is properly propagated by checking that empty buckets were created. | ||
*/ | ||
@OpenSearchIntegTestCase.SuiteScopeTestCase | ||
public class ShardReduceIT extends GeoModulePluginIntegTestCase { | ||
|
||
private IndexRequestBuilder indexDoc(String date, int value) throws Exception { | ||
return client().prepareIndex("idx") | ||
.setSource( | ||
jsonBuilder().startObject() | ||
.field("value", value) | ||
.field("ip", "10.0.0." + value) | ||
.field("location", Geohash.stringEncode(5, 52, Geohash.PRECISION)) | ||
.field("date", date) | ||
.field("term-l", 1) | ||
.field("term-d", 1.5) | ||
.field("term-s", "term") | ||
.startObject("nested") | ||
.field("date", date) | ||
.endObject() | ||
.endObject() | ||
); | ||
} | ||
|
||
@Override | ||
public void setupSuiteScopeCluster() throws Exception { | ||
assertAcked( | ||
prepareCreate("idx").setMapping( | ||
"nested", | ||
"type=nested", | ||
"ip", | ||
"type=ip", | ||
"location", | ||
"type=geo_point", | ||
"term-s", | ||
"type=keyword" | ||
) | ||
); | ||
|
||
indexRandom(true, indexDoc("2014-01-01", 1), indexDoc("2014-01-02", 2), indexDoc("2014-01-04", 3)); | ||
ensureSearchable(); | ||
} | ||
|
||
public void testGeoHashGrid() throws Exception { | ||
SearchResponse response = client().prepareSearch("idx") | ||
.setQuery(QueryBuilders.matchAllQuery()) | ||
.addAggregation( | ||
AggregationBuilders.geohashGrid("grid") | ||
.field("location") | ||
.subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY).minDocCount(0)) | ||
) | ||
.get(); | ||
|
||
assertSearchResponse(response); | ||
|
||
GeoGrid grid = response.getAggregations().get("grid"); | ||
Histogram histo = grid.getBuckets().iterator().next().getAggregations().get("histo"); | ||
assertThat(histo.getBuckets().size(), equalTo(4)); | ||
} | ||
|
||
public void testGeoTileGrid() throws Exception { | ||
SearchResponse response = client().prepareSearch("idx") | ||
.setQuery(QueryBuilders.matchAllQuery()) | ||
.addAggregation( | ||
AggregationBuilders.geotileGrid("grid") | ||
.field("location") | ||
.subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY).minDocCount(0)) | ||
) | ||
.get(); | ||
|
||
assertSearchResponse(response); | ||
|
||
GeoGrid grid = response.getAggregations().get("grid"); | ||
Histogram histo = grid.getBuckets().iterator().next().getAggregations().get("histo"); | ||
assertThat(histo.getBuckets().size(), equalTo(4)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...lusterTest/java/org/opensearch/geo/search/aggregations/metrics/GeoCentroidITTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.geo.search.aggregations.metrics; | ||
|
||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.common.geo.GeoPoint; | ||
import org.opensearch.geo.search.aggregations.bucket.geogrid.GeoGrid; | ||
import org.opensearch.geo.tests.common.AggregationBuilders; | ||
import org.opensearch.search.aggregations.metrics.GeoCentroid; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
|
||
import java.util.List; | ||
|
||
import static org.hamcrest.Matchers.closeTo; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.opensearch.search.aggregations.AggregationBuilders.geoCentroid; | ||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse; | ||
|
||
@OpenSearchIntegTestCase.SuiteScopeTestCase | ||
public class GeoCentroidITTestCase extends AbstractGeoAggregatorModulePluginTestCase { | ||
private static final String aggName = "geoCentroid"; | ||
|
||
public void testSingleValueFieldAsSubAggToGeohashGrid() throws Exception { | ||
SearchResponse response = client().prepareSearch(HIGH_CARD_IDX_NAME) | ||
.addAggregation( | ||
AggregationBuilders.geohashGrid("geoGrid") | ||
.field(SINGLE_VALUED_FIELD_NAME) | ||
.subAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME)) | ||
) | ||
.get(); | ||
assertSearchResponse(response); | ||
|
||
GeoGrid grid = response.getAggregations().get("geoGrid"); | ||
assertThat(grid, notNullValue()); | ||
assertThat(grid.getName(), equalTo("geoGrid")); | ||
List<? extends GeoGrid.Bucket> buckets = grid.getBuckets(); | ||
for (GeoGrid.Bucket cell : buckets) { | ||
String geohash = cell.getKeyAsString(); | ||
GeoPoint expectedCentroid = expectedCentroidsForGeoHash.get(geohash); | ||
GeoCentroid centroidAgg = cell.getAggregations().get(aggName); | ||
assertThat( | ||
"Geohash " + geohash + " has wrong centroid latitude ", | ||
expectedCentroid.lat(), | ||
closeTo(centroidAgg.centroid().lat(), GEOHASH_TOLERANCE) | ||
); | ||
assertThat( | ||
"Geohash " + geohash + " has wrong centroid longitude", | ||
expectedCentroid.lon(), | ||
closeTo(centroidAgg.centroid().lon(), GEOHASH_TOLERANCE) | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.