我需要在大约50k地形多边形(在ES上存储为geo_shape多边形)的数据库上建立查询,并在其中给出一个点,并返回包含该点的每个多边形。
我设法使用渗滤查询(下面的示例)来做到这一点,但我读到渗滤查询扩展性不好的地方。
有没有更有效的方法来实现此行为?
使用渗滤剂的示例:
PUT geo_demo
{
"mappings": {
"properties": {
"thepoly": {
"type": "percolator"
},
"thepoint": {
"type": "geo_point"
}
}
}
}
#region 1 (red)
POST /geo_demo/_doc/1
{
"thepoly": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"thepoint": {
"points": [
"-23.573978,-46.664806",
"-23.583978,-46.664806",
"-23.583978,-46.658806",
"-23.573978,-46.658806",
"-23.573978,-46.664806"
]
}
}
}
}
}
}
#region 2 (green)
POST /geo_demo/_doc/2
{
"thepoly": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"thepoint": {
"points": [
"-23.579978,-46.664806",
"-23.583978,-46.664806",
"-23.583978,-46.652806",
"-23.579978,-46.652806",
"-23.579978,-46.664806"
]
}
}
}
}
}
}
#should match doc/1 only
GET /geo_demo/_search
{
"query": {
"percolate": {
"field": "thepoly",
"document": {
"thepoint": "-23.577007,-46.661811"
}
}
}
}
#should match both doc/1 and doc/2
GET /geo_demo/_search
{
"query": {
"percolate": {
"field": "thepoly",
"document": {
"thepoint": "-23.582002,-46.661811"
}
}
}
}
#should match doc/2 only
GET /geo_demo/_search
{
"query": {
"percolate": {
"field": "thepoly",
"document": {
"thepoint": "-23.582041,-46.655717"
}
}
}
}
#should match none
GET /geo_demo/_search
{
"query": {
"percolate": {
"field": "thepoly",
"document": {
"thepoint": "-23.576771,-46.655674"
}
}
}
}
答案 0 :(得分:0)
除非您有充分的理由,否则您几乎不需要弹性评估。
对于50K多边形,您可以轻松地将它们放在堆中,或将每个多边形分解为地质哈希表。
您可以拥有一个以geohash为键,多边形id为值的堆内地图。
当有点进入时,您首先要计算地理哈希值,然后使用Map#get
来检查该点在地图上还是包含该点的多边形。