Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geo_shape query doesn't behave the same way when passing a rectangle that crosses the dateline as an Envelope or as a Polygon #46435

Closed
MohamedHamouGisaia opened this issue Sep 6, 2019 · 2 comments
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)

Comments

@MohamedHamouGisaia
Copy link

Elasticsearch version : Version: 7.3.1, Build: default/tar/4749ba6/2019-08-19T20:19:25.651794Z, JVM: 1.8.0_181

JVM version :
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

OS version:
Linux tizintest 4.15.0-58-generic #64-Ubuntu SMP Tue Aug 6 11:12:41 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Description of the problem including expected versus actual behavior:

Supposing I index a Polygon P in a test index. Then I apply 2 geo queries with the same polygon QP that crosses the dateline and where P is within QP.

  • First query is a geo_shape (within) query on the shape field where QP is an envelope
  • Second query is a geo_shape (within) query on the shape field where QP is a Polygon

image

  • In the first query I obtained the desired result : the Polygon P is returned
  • In the second query I have 0 result. The polygon P is not returned. The orientation of the QP polygon seems to be ignored, so it's the small polygon between longitues [25, 40] that is used. This is what I understood from @imotov comment in #35813

Therefore, 2 within queries on the same zone QP have different results according to the chosen type for QP

Steps to reproduce:

  1. Indexing data
curl -X PUT "localhost:9200/test" -H 'Content-Type: application/json' -d'
{
    "mappings": {
         "properties": {
                "shape": {
                    "type": "geo_shape"
                }
          }
    }
}
'
curl -X PUT "localhost:9200/test/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
    "shape": {
        "type": "polygon",
        "coordinates": [[[20, 20], [-20, 20], [-20, -20], [20, -20], [20, 20]]]
    }
}
'
  1. geo_shape query using an envelope
curl -X GET "localhost:9200/test/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query":{
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_shape": {
                    "shape": {
                        "shape": {
                            "type": "envelope",
                            "coordinates" : [[40,30], [25,-30]]
                        },
                        "relation": "within"
                    }
                }
            }
        }
    }
}
'
  1. geo_shape query using a polygon
curl -X GET "localhost:9200/test/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query":{
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_shape": {
                    "shape": {
                        "shape": {
                            "type": "polygon",
                            "coordinates" : [[[25,-30],[25,30],[40,30],[40,-30],[25,-30]]]
                        },
                        "relation": "within"
                    }
                }
            }
        }
    }
}
'

Changing the order of coordinates has no effect :

curl -X GET "localhost:9200/test/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query":{
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_shape": {
                    "shape": {
                        "shape": {
                            "type": "polygon",
                            "coordinates" : [[[25,-30],[40,-30],[40,30],[25,30],[25,-30]]]
                        },
                        "relation": "within"
                    }
                }
            }
        }
    }
}
'
@danielmitterdorfer danielmitterdorfer added the :Analytics/Geo Indexing, search aggregations of geo points and shapes label Sep 6, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo

@rjernst rjernst added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label May 4, 2020
@iverase
Copy link
Contributor

iverase commented Apr 21, 2023

I had a look into this issue and I think the issue here is the expectations around polygon crossing the dateline. Elasticsearch will only consider breaking a polygon across the dateline if the difference between the minimum and maximum longitude is bigger than 180 degrees.

The polygon in the query has a minimum longitude of 25 and a maximum longitude of 40, so it will never be consider as crossing the dateline. In other words, you can express the provided bounding box as a polygon.

Therefore I am closing this issue.

@iverase iverase closed this as completed Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)
Projects
None yet
Development

No branches or pull requests

5 participants