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


Java GeoHashGrid类代码示例

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


GeoHashGrid类属于org.elasticsearch.search.aggregations.bucket.geogrid包,在下文中一共展示了GeoHashGrid类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testUnmapped

import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid; //导入依赖的package包/类
public void testUnmapped() throws Exception {
    for (int precision = 1; precision <= PRECISION; precision++) {
        SearchResponse response = client().prepareSearch("idx_unmapped")
                .addAggregation(geohashGrid("geohashgrid")
                        .field("location")
                        .precision(precision)
                )
                .execute().actionGet();

        assertSearchResponse(response);

        GeoHashGrid geoGrid = response.getAggregations().get("geohashgrid");
        assertThat(geoGrid.getBuckets().size(), equalTo(0));
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:GeoHashGridIT.java

示例4: 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

示例5: 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 = aggs.get(name);
        List<Bucket> buckets = new ArrayList<>();
        grid.getBuckets().stream().filter(bucket -> bucket.getDocCount() > 0).forEach(bucket -> {
            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,代码行数:23,代码来源:GeoHashGridAggregationConverter.java

示例6: 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

示例7: 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);
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:10,代码来源:ElasticsearchGraphQueryIterable.java

示例8: testGeoHashGrid

import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid; //导入依赖的package包/类
public void testGeoHashGrid() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .setQuery(QueryBuilders.matchAllQuery())
            .addAggregation(geohashGrid("grid").field("location")
                    .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0)))
            .execute().actionGet();

    assertSearchResponse(response);

    GeoHashGrid grid = response.getAggregations().get("grid");
    Histogram histo = grid.getBuckets().iterator().next().getAggregations().get("histo");
    assertThat(histo.getBuckets().size(), equalTo(4));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:ShardReduceIT.java

示例9: 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

示例10: 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

示例11: 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());
    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:11,代码来源:AggregationTest.java

示例12: 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());
    }
}
 
开发者ID:selvakumarEsra,项目名称:es4sql,代码行数:11,代码来源:AggregationTest.java

示例13: 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 = aggs.get(name);
        List<Bucket> buckets = new ArrayList<>();
        grid.getBuckets().stream().filter(bucket -> bucket.getDocCount() > 0).forEach(bucket -> {
            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,代码行数:35,代码来源:GeoHashGridStatsAggregationConverter.java

示例14: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。