gpt4 book ai didi

elasticsearch - 如何在日期线上使用多边形搜索地理位置?

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

如何使用Java API在日期线(国际日期线,或180和-180经度)上用多边形搜索地理位置?

大家好:

我使用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区域中的文档,A dteline上的区域。
但是根据结果,经度为82,98,-121等,但在[100,180]到[-180,-170]之间没有文档,因此我认为实际上B区域中的 ES搜索(它分析错误的多边形)。

我在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:


  • Outer Ring - Counterclockwise

  • Inner Ring(s) / Holes - Clockwise


  • 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.



    但这是针对geoShape数据类型的,而我的文档所在的位置是geopoint,我在geopoints的网页上找不到类似的词(www.elastic.co/guide/en/elasticsearch/reference/2.1/geo- point.html)。

    我尝试了一些方法:
    1.逆时针和顺时针顶点顺序;
    2.从矩形的每个顶点开始;
    3.用190 lon替换-170 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_polygon类型的geo_point查询不起作用
    在日期范围内。您要么必须:

  • 手动将多边形分成2个并使用 bool(boolean) AND将其合并;
  • geo_points重新索引为geo_shapes(建议设置points_only = true),并使用geo_shape(www.elastic.co/guide/zh-CN/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(在describe.elastic.co上)!

    关于elasticsearch - 如何在日期线上使用多边形搜索地理位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34768911/

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