我需要在具有大约 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"
}
}
}
}