使用 shuf 来打乱一个文件中的行或是选择文件中一个随机的行。

我想测试下Geo Aaggregation。下面是我的思路

Elasticsearch | 作者 BEATA | 发布于2016年01月22日 | 阅读数:5502

1.测试数据:{"address":{"location":[{"lat":0.0,"lon":0.0},{"lat":0.0,"lon":0.0}]}}
{"address":{"location":[{"lat":1.0,"lon":1.0},{"lat":1.0,"lon":1.0}]}}
{"address":{"location":[{"lat":2.0,"lon":2.0},{"lat":2.0,"lon":2.0}]}}
{"address":{"location":[{"lat":3.0,"lon":3.0},{"lat":3.0,"lon":3.0}]}}
{"address":{"location":[{"lat":4.0,"lon":4.0},{"lat":4.0,"lon":4.0}]}}
2.测试方法
Client client = new TransportClient().addTransportAddresses(new InetSocketTransportAddress("127.0.0.1", 9300));

AggregationBuilder aggregation =
AggregationBuilders
.geoDistance("agg")
.field("address.location")
.point(new GeoPoint(0,5))
.unit(DistanceUnit.KILOMETERS)
.addUnboundedTo(30.0)
.addRange(30.0, 40.0)
.addRange(40.0, 500.0);

SearchResponse sr = client.prepareSearch("mytest").setTypes("logs")
.addAggregation(aggregation)
.setSize(20)
.execute()
.actionGet();

System.out.println(sr.toString());
Range agg = sr.getAggregations().get("agg");

for (Range.Bucket entry : agg.getBuckets()) {

String key = entry.getKey(); // key as String
Number from = (Number) entry.getFrom(); // bucket from value
Number to = (Number) entry.getTo(); // bucket to value
long docCount = entry.getDocCount(); // Doc count

System.out.println("key:"+key+";from:"+from+";to:"+to+";docCount:"+docCount);
}

SearchHits hits = sr.getHits();

if (null == hits || hits.totalHits() == 0) {

System.out.println("对不起,您没有查询到结果!!");

}
else {

for (SearchHit hit : hits) {

String json = hit.getSourceAsString();
System.out.println(json);
}
}
3.测试结果docCount都等于0,我觉得好像在哪用的不对,请大家帮忙看下
已邀请:

要回复问题请先登录注册