Description
Elasticsearch version: 2.2 - 5.1
JVM version:
openjdk version "1.8.0_72-internal"
OpenJDK Runtime Environment (build 1.8.0_72-internal-b15)
OpenJDK 64-Bit Server VM (build 25.72-b15, mixed mode)
OS version:
Alpine Linux v3.4 in Docker 1.12.5 Stable on Mac OS 10.12.2
Description of the problem including expected versus actual behavior:
Envelopes create a bounding box that won't cross longitude 180 ( or -180, roughly the international dateline).
Steps to reproduce:
- Store geo shape polygon at coordinates [[179,1], [179, -1], [-179, -1], [-179, 1], [179, 1]] in an index.
- Run a geo_shape query against the index with an envelope of [[170, 10], [-170, -10]]
- The polygon that was stored should return but is not.
ShapBuilder, in parseEnvelope, modifies the upper left and lower right coordinates. It sets the upper left to the minimum longitude and maximum latitude of the coordinates provided. Lower right gets the maximum longitude and minimum latitude of the coordinates provided. This means that an envelope of [[170, 10], [10, -10]] will not find a polygon with a coordinate or (179,1) as part of a geo_shape query using envelope because the bounds of the envelope will be modified to [[10, 10], [170, -10]]. It's fine to modify the latitude coordinates setting the maximum to the upper left, and the minimum to the upper right, but the longitude coordinates should not be changed.
Here is a simple Sense script that demonstrates the problem. It creates two polygons on the equator, one on the prime meridian and one on the international dateline. It then searches the polygon on the international dateline using an identical polygon and envelope search. The polygon search returns the correct document, the envelope search returns the wrong document.
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"location": {
"type": "geo_shape"
}
}
}
}
}
PUT my_index/my_type/1
{
"text": "Geo-shape as an polygon on dateline and equator",
"location": {
"type":"polygon",
"coordinates":[[
[179,1],
[179,-1],
[-179,-1],
[-179,1],
[179,1]
]]
}
}
PUT my_index/my_type/2
{
"text": "Geo-shape as an polygon on prime meridian and equator",
"location": {
"type":"polygon",
"coordinates":[[
[1,1],
[1,-1],
[-1,-1],
[-1,1],
[1,1]
]]
}
}
GET my_index/_search
{
"query":{
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_shape": {
"location": {
"shape": {
"type": "polygon",
"coordinates" : [[
[170, 10],
[170, -10],
[-170, -10],
[-170, 10],
[170, 10]
]]
},
"relation": "within"
}
}
}
}
}
}
GET my_index/_search
{
"query":{
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_shape": {
"location": {
"shape": {
"type": "envelope",
"coordinates" : [
[170, 10],
[-170, -10]
]
},
"relation": "within"
}
}
}
}
}
}