当前位置: 首页>>代码示例>>Java>>正文


Java GeoHashGrid.getBuckets方法代码示例

本文整理汇总了Java中org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid.getBuckets方法的典型用法代码示例。如果您正苦于以下问题:Java GeoHashGrid.getBuckets方法的具体用法?Java GeoHashGrid.getBuckets怎么用?Java GeoHashGrid.getBuckets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid的用法示例。


在下文中一共展示了GeoHashGrid.getBuckets方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:GeoCentroidIT.java

示例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);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:GeoHashGridIT.java

示例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);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:GeoHashGridIT.java

示例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;
}
 
开发者ID:scaleset,项目名称:scaleset-search,代码行数:25,代码来源:GeoHashGridAggregationConverter.java

示例5: 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));
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:GeoHashGridIT.java

示例6: 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);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:GeoHashGridIT.java

示例7: 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;
}
 
开发者ID:scaleset,项目名称:scaleset-search,代码行数:37,代码来源:GeoHashGridStatsAggregationConverter.java


注:本文中的org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid.getBuckets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。