gpt4 book ai didi

elasticsearch - 如何在Elasticsearch中查找包含给定点的多边形

转载 作者:行者123 更新时间:2023-12-02 22:35:02 24 4
gpt4 key购买 nike

我需要在大约50k地形多边形(在ES上存储为geo_shape多边形)的数据库上构建查询,并在其中给出一个点,并返回包含该点的每个多边形。

我设法使用渗滤查询(下面的示例)来做到这一点,但是我读到渗滤查询扩展性不好的地方。

有没有更有效的方法来实现此行为?

使用渗滤液的示例:

Demo polygons

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"
}
}
}
}

最佳答案

除非您有充分的理由,否则您几乎不需要 flex 评估。

对于50K多边形,您可以轻松地将它们放在堆中,也可以将每个多边形分解为一系列的哈希表。

您可以拥有一个以geohash为键,多边形id为值的堆内 map 。

当有点进入时,您首先要计算geohash,然后使用Map#get来检查该点是否在 map 上或包含该点的多面体。

关于elasticsearch - 如何在Elasticsearch中查找包含给定点的多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58883377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com