本文整理汇总了Java中org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid.Bucket方法的典型用法代码示例。如果您正苦于以下问题:Java GeoHashGrid.Bucket方法的具体用法?Java GeoHashGrid.Bucket怎么用?Java GeoHashGrid.Bucket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid
的用法示例。
在下文中一共展示了GeoHashGrid.Bucket方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSingleValueFieldAsSubAggToGeohashGrid
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid; //导入方法依赖的package包/类
public void testSingleValueFieldAsSubAggToGeohashGrid() throws Exception {
SearchResponse response = client().prepareSearch(HIGH_CARD_IDX_NAME)
.addAggregation(geohashGrid("geoGrid").field(SINGLE_VALUED_FIELD_NAME)
.subAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME)))
.execute().actionGet();
assertSearchResponse(response);
GeoHashGrid grid = response.getAggregations().get("geoGrid");
assertThat(grid, notNullValue());
assertThat(grid.getName(), equalTo("geoGrid"));
List<GeoHashGrid.Bucket> buckets = grid.getBuckets();
for (int i=0; i < buckets.size(); ++i) {
GeoHashGrid.Bucket cell = buckets.get(i);
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));
}
}
示例2: testMultivalued
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid; //导入方法依赖的package包/类
public void testMultivalued() throws Exception {
for (int precision = 1; precision <= PRECISION; precision++) {
SearchResponse response = client().prepareSearch("multi_valued_idx")
.addAggregation(geohashGrid("geohashgrid")
.field("location")
.precision(precision)
)
.execute().actionGet();
assertSearchResponse(response);
GeoHashGrid geoGrid = response.getAggregations().get("geohashgrid");
for (GeoHashGrid.Bucket cell : geoGrid.getBuckets()) {
String geohash = cell.getKeyAsString();
long bucketCount = cell.getDocCount();
int expectedBucketCount = multiValuedExpectedDocCountsForGeoHash.get(geohash);
assertNotSame(bucketCount, 0);
assertEquals("Geohash " + geohash + " has wrong doc count ",
expectedBucketCount, bucketCount);
}
}
}
示例3: testPartiallyUnmapped
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid; //导入方法依赖的package包/类
public void testPartiallyUnmapped() throws Exception {
for (int precision = 1; precision <= PRECISION; precision++) {
SearchResponse response = client().prepareSearch("idx", "idx_unmapped")
.addAggregation(geohashGrid("geohashgrid")
.field("location")
.precision(precision)
)
.execute().actionGet();
assertSearchResponse(response);
GeoHashGrid geoGrid = response.getAggregations().get("geohashgrid");
for (GeoHashGrid.Bucket cell : geoGrid.getBuckets()) {
String geohash = cell.getKeyAsString();
long bucketCount = cell.getDocCount();
int expectedBucketCount = expectedDocCountsForGeoHash.get(geohash);
assertNotSame(bucketCount, 0);
assertEquals("Geohash " + geohash + " has wrong doc count ",
expectedBucketCount, bucketCount);
}
}
}
示例4: convertResult
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid; //导入方法依赖的package包/类
@Override
public AggregationResults convertResult(ResultsConverter resultsConverter, Aggregation
aggregation, Aggregations aggs) {
String name = aggregation.getName();
AggregationResults result = null;
if (aggs.get(name) instanceof GeoHashGrid) {
GeoHashGrid grid = (GeoHashGrid) (aggs.get(name));
List<Bucket> buckets = new ArrayList<>();
for (GeoHashGrid.Bucket bucket : grid.getBuckets()) {
if (bucket.getDocCount() > 0) {
Bucket b = new Bucket(bucket.getKey(), bucket.getDocCount());
buckets.add(b);
for (Aggregation subAgg : aggregation.getAggs().values()) {
AggregationResults subResults = resultsConverter.convertResults(subAgg, bucket.getAggregations());
if (subResults != null) {
b.getAggs().put(subAgg.getName(), subResults);
}
}
}
}
result = new AggregationResults(name, buckets);
}
return result;
}
示例5: getAverageGeoPointFromBuckets
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid; //导入方法依赖的package包/类
private static GeoPoint getAverageGeoPointFromBuckets(List<MultiBucketsAggregation.Bucket> buckets) {
List<GeoPoint> geoPoints = new ArrayList<>();
for (MultiBucketsAggregation.Bucket b : buckets) {
GeoHashGrid.Bucket gb = (GeoHashGrid.Bucket) b;
org.elasticsearch.common.geo.GeoPoint gp = (org.elasticsearch.common.geo.GeoPoint) gb.getKey();
geoPoints.add(new GeoPoint(gp.getLat(), gp.getLon()));
}
return GeoPoint.calculateCenter(geoPoints);
}
示例6: testSimple
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid; //导入方法依赖的package包/类
public void testSimple() throws Exception {
for (int precision = 1; precision <= PRECISION; precision++) {
SearchResponse response = client().prepareSearch("idx")
.addAggregation(geohashGrid("geohashgrid")
.field("location")
.precision(precision)
)
.execute().actionGet();
assertSearchResponse(response);
GeoHashGrid geoGrid = response.getAggregations().get("geohashgrid");
List<Bucket> buckets = geoGrid.getBuckets();
Object[] propertiesKeys = (Object[]) geoGrid.getProperty("_key");
Object[] propertiesDocCounts = (Object[]) geoGrid.getProperty("_count");
for (int i = 0; i < buckets.size(); i++) {
GeoHashGrid.Bucket cell = buckets.get(i);
String geohash = cell.getKeyAsString();
long bucketCount = cell.getDocCount();
int expectedBucketCount = expectedDocCountsForGeoHash.get(geohash);
assertNotSame(bucketCount, 0);
assertEquals("Geohash " + geohash + " has wrong doc count ",
expectedBucketCount, bucketCount);
GeoPoint geoPoint = (GeoPoint) propertiesKeys[i];
assertThat(stringEncode(geoPoint.lon(), geoPoint.lat(), precision), equalTo(geohash));
assertThat((long) propertiesDocCounts[i], equalTo(bucketCount));
}
}
}
示例7: testTopMatch
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid; //导入方法依赖的package包/类
public void testTopMatch() throws Exception {
for (int precision = 1; precision <= PRECISION; precision++) {
SearchResponse response = client().prepareSearch("idx")
.addAggregation(geohashGrid("geohashgrid")
.field("location")
.size(1)
.shardSize(100)
.precision(precision)
)
.execute().actionGet();
assertSearchResponse(response);
GeoHashGrid geoGrid = response.getAggregations().get("geohashgrid");
//Check we only have one bucket with the best match for that resolution
assertThat(geoGrid.getBuckets().size(), equalTo(1));
for (GeoHashGrid.Bucket cell : geoGrid.getBuckets()) {
String geohash = cell.getKeyAsString();
long bucketCount = cell.getDocCount();
int expectedBucketCount = 0;
for (ObjectIntCursor<String> cursor : expectedDocCountsForGeoHash) {
if (cursor.key.length() == precision) {
expectedBucketCount = Math.max(expectedBucketCount, cursor.value);
}
}
assertNotSame(bucketCount, 0);
assertEquals("Geohash " + geohash + " has wrong doc count ",
expectedBucketCount, bucketCount);
}
}
}
示例8: geoHashGrid
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid; //导入方法依赖的package包/类
@Test
public void geoHashGrid() throws SQLFeatureNotSupportedException, SqlParseException {
Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/location GROUP BY geohash_grid(field='center',precision=5) ", TEST_INDEX));
InternalGeoHashGrid grid = result.get("geohash_grid(field=center,precision=5)");
Collection<GeoHashGrid.Bucket> buckets = grid.getBuckets();
for (GeoHashGrid.Bucket bucket : buckets) {
Assert.assertTrue(bucket.getKeyAsString().equals("w2fsm") || bucket.getKeyAsString().equals("w0p6y") );
Assert.assertEquals(1,bucket.getDocCount());
}
}
示例9: geoHashGrid
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid; //导入方法依赖的package包/类
@Test
public void geoHashGrid() throws SQLFeatureNotSupportedException, SqlParseException {
Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/location GROUP BY geohash_grid(field='center',precision=5) ", TestsConstants.TEST_INDEX));
InternalGeoHashGrid grid = result.get("geohash_grid(field=center,precision=5)");
Collection<GeoHashGrid.Bucket> buckets = grid.getBuckets();
for (GeoHashGrid.Bucket bucket : buckets) {
Assert.assertTrue(bucket.getKey().toString().equals("[4.98779296875, 105.00732421875]") || bucket.getKey().toString().equals("[0.50537109375, 100.48095703125]") );
Assert.assertEquals(1,bucket.getDocCount());
}
}
示例10: convertResult
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid; //导入方法依赖的package包/类
@Override
public AggregationResults convertResult(ResultsConverter resultsConverter, Aggregation
aggregation, Aggregations aggs) {
String name = aggregation.getName();
AggregationResults result = null;
if (aggs.get(name) instanceof GeoHashGrid) {
GeoHashGrid grid = (GeoHashGrid) (aggs.get(name));
List<Bucket> buckets = new ArrayList<>();
for (GeoHashGrid.Bucket bucket : grid.getBuckets()) {
if (bucket.getDocCount() > 0) {
Bucket b = new Bucket(bucket.getKey(), bucket.getDocCount());
Stats latStats = bucket.getAggregations().get("lat_stats");
Stats lonStats = bucket.getAggregations().get("lon_stats");
double minx = lonStats.getMin();
double maxx = lonStats.getMax();
double miny = latStats.getMin();
double maxy = latStats.getMax();
double cx = lonStats.getAvg();
double cy = latStats.getAvg();
Envelope bbox = new Envelope(minx, maxx, miny, maxy);
b.put("bbox", bbox);
b.put("centroid", new Coordinate(cx, cy));
buckets.add(b);
for (Aggregation subAgg : aggregation.getAggs().values()) {
AggregationResults subResults = resultsConverter.convertResults(subAgg, bucket.getAggregations());
if (subResults != null) {
b.getAggs().put(subAgg.getName(), subResults);
}
}
}
}
result = new AggregationResults(name, buckets);
}
return result;
}