2

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

1 回答 1

-1

除非你有充分的理由,否则你几乎不需要 elasticsearch。

对于 50K 多边形,您可以轻松地将它们保存在堆中,或者将每个多边形分解为 geohashes 列表。

您可以有一个以 geohash 作为键,多边形 id 作为值的堆内映射。

当你有点进来时,你首先计算geohash,然后Map#get用来检查该点在地图中或者哪个多边形包含这个点。

于 2019-11-15T21:06:17.127 回答