我正在建立一个财产灌溉网站,该网站将存储数百个属性的thosuands。为了映射区域,我使用Elastic Search的GEO Hashing来减少给定缩放级别返回的匹配数。
生成哈希的代码如下:
`GET _search
{
"from": 0,
"size": 0,
"query": {
"match_all": {}
},
"filter": {
"and": [{
"range": {
"property.price": {
"lte": 1000000000
}
}
}, {
"geo_bounding_box": {
"property.location": {
"top_left": {
"lat": 42.88679,
"lon": -73.5081419
},
"bottom_right": {
"lat": 41.2390897,
"lon": -69.9279921
}
}
}
}, {
"term": {
"property.rental": false
}
}, {
"term": {
"property.country": "US"
}
}]
},
"sort": [{
"property.price": "asc"
}],
"facets": {
"stat1": {
"statistical": {
"field": "price"
}
}
},
"aggs": {
"geohash": {
"filter": {
"geo_bounding_box": {
"property.location": {
"top_left": {
"lat": 42.88679,
"lon": -73.5081419
},
"bottom_right": {
"lat": 41.2390897,
"lon": -69.9279921
}
}
}
},
"aggregations": {
"locations": {
"geohash_grid": {
"field": "location",
"precision": 8
}
}
}
}
}
}`
生成的JSON会返回每个GeoHash的匹配数并且正在运行,除了似乎没有任何方法可以在结果中包含属性详细信息,或者包含一个ID以便在单击时返回到它? / p>
结果如下:
`{
"took": 94,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 13,
"max_score": 0,
"hits": []
},
"facets": {
"stat1": {
"_type": "statistical",
"count": 50,
"total": 90640800,
"min": 1,
"max": 19500000,
"mean": 1812816,
"sum_of_squares": 628677324820002,
"variance": 9287244646544.04,
"std_deviation": 3047498.0962330457
}
},
"aggregations": {
"geohash": {
"doc_count": 16,
"locations": {
"buckets": [
{
"key": "drt05n43",
"doc_count": 2
},
{
"key": "drt0v0q8",
"doc_count": 1
},
{
"key": "drt0sr3e",
"doc_count": 1
},
{
"key": "drt0kgr8",
"doc_count": 1
},
{
"key": "drt07sdk",
"doc_count": 1
},
{
"key": "drt075vd",
"doc_count": 1
},
{
"key": "drt05n19",
"doc_count": 1
},
{
"key": "drt05jgv",
"doc_count": 1
},
{
"key": "drsbrgvh",
"doc_count": 1
},
{
"key": "drmpgznd",
"doc_count": 1
},
{
"key": "drmpft6c",
"doc_count": 1
},
{
"key": "drmpe6bg",
"doc_count": 1
},
{
"key": "drmp7ybz",
"doc_count": 1
},
{
"key": "drmgkj77",
"doc_count": 1
},
{
"key": "drkzzj3d",
"doc_count": 1
}
]
}
}
} }`
任何有关向结果中添加其他属性数据的帮助都将非常感谢。
谢谢:)
P.S。抱歉代码意图,使用JSON进行SO代码检测有点奇怪。
答案 0 :(得分:0)
您可以使用嵌套聚合: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/nested-aggregation.html
使用http://www.fullscale.co/elasticjs/
中的elastic.jsejs.GeoHashGridAggregation('Geohash-Grid')
.field('Geohash')
.precision(precision)
.aggregation(
ejs.TermsAggregation('HouseType').field('HouseType')
)
.aggregation(
ejs.TermsAggregation('HouseColor').field('HouseColor')
)
);
但这只是一个例子。然后输出将具有与每个geohash匹配的文档的嵌套聚合计数。