如何跨日期线搜索多边形的地理点?

How to search geo-point with polygon across dateline?

如何跨日期变更线(国际日期变更线,或 180 度和 -180 度经度)使用多边形搜索地理点使用 java api?

大家好:

我使用 ElasticSearch 2.1 及其 java api,我想 使用多边形地理过滤器搜索文档(多边形通常是矩形),但是当多边形跨越日期变更线(国际日期变更线,或180和-180经度)时,出错。例如: 我的代码:

BoolQueryBuilder mustQuery = QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery());
......
GeoPolygonQueryBuilder qb = QueryBuilders.geoPolygonQuery("description.device_location.es_geo");

qb.addPoint(0,100);//the left down vertex of the polygon(rectangle),patams is (lat , lon)
qb.addPoint(0,-170);//right down
qb.addPoint(80,-170);//right up
qb.addPoint(80,100);//left up
qb.addPoint(0,100);//left down,same to the first vertex

mustQuery = mustQuery.must(qb);
SearchResponse searchResponse = EsClient.getClient().prepareSearch(Config.indexName)
.setTypes(Config.typeName)
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(mustQuery)
.setFrom(0).setSize(size).setExplain(true)
.execute()
.actionGet();

示意图:

I want search in A area,but ES search in B area in fact

如上图,我提供ES点[0,100],[0,-170],[80,-170],[80,100],[0,100]来描述A区域,我想要 A 区域 中的文档,跨 dteline 的区域。 但是根据结果,有经度82,98,-121等,但是[100,180]和[-180,-170]之间没有文档,所以我想ES实际上是在B区搜索(分析多边形出错)

我搜索解决方案,在ES的网站上,我找到了一些关于这个问题的词: (表格 www.elastic.co/guide/en/elasticsearch/reference/2.1/geo-shape.html)

IMPORTANT NOTE: GeoJSON does not mandate a specific order for vertices thus ambiguous polygons around the dateline and poles are possible. To alleviate ambiguity the Open Geospatial Consortium (OGC) Simple Feature Access specification defines the following vertex ordering:

For polygons that do not cross the dateline, vertex order will not matter in Elasticsearch. For polygons that do cross the dateline, Elasticsearch requires vertex ordering to comply with the OGC specification. Otherwise, an unintended polygon may be created and unexpected query/filter results will be returned.

The following provides an example of an ambiguous polygon. Elasticsearch will apply OGC standards to eliminate ambiguity resulting in a polygon that crosses the dateline.

但这是geo-Shape数据类型,我的文档位置是geo-point,我在geo-points的网页上找不到类似的词(www.elastic.co/guide/en/elasticsearch/reference/2.1 /geo-point.html).

我尝试了一些方法: 1.逆时针和顺时针顶点顺序; 2.从矩形的每个顶点开始; 3.将-170 lon替换为190 lon; 但是这些方法都不行。

有谁知道如何跨日期线搜索多边形吗? 谢谢! (不好意思,我是中国开发者,英语说得不好,如有不当之处,请多多指教或评论,谢谢。)

Here is the translated text of Chinese.Chinese characters couldn't be insert to question direct.

我是提问者,我已经有了答案。 我在 https://discuss.elastic.co/t/search-geo-point-with-polygon-across-dateline/39103/3 上问过这个问题,并在那里得到答案。 以前,我想过如果没有完美的解决方案,我可以通过日期线将多边形拆分为2。我知道ES不支持搜索geo-point现在跨越日期变更线的多边形:

目前 geo_polygongeo_point 类型的查询不起作用 跨越日期变更线。您将必须:

  1. 手动将多边形拆分为 2 并使用布尔 AND 组合它们;
  2. geo_points 重新索引为 geo_shapes(推荐设置 points_only = true)并使用 geo_shape(www.elastic.co/guide/en/elasticsearch/reference/2.1/ geo-shape.html)查询.

但是如果你知道多边形是 矩形,您可以使用 geo_bounding_box (www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html) 查询 处理日期线(如您的示例所示)。

感谢@nknize 和@medcl1(在 discuss.elastic.co)!