# GeoShape Polygon Query not returning expected documents

**URL:** <https://discuss.elastic.co/t/geoshape-polygon-query-not-returning-expected-documents/368630>\
**Category:** Elasticsearch\
**Created:** [October 10, 2024, 12:44pm UTC](https://discuss.elastic.co/t/geoshape-polygon-query-not-returning-expected-documents/368630 "2024-10-10T12:44:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shaun1](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@Shaun1](https://discuss.elastic.co/u/Shaun1)\
**Post date:** [October 10, 2024, 12:44pm UTC](https://discuss.elastic.co/t/geoshape-polygon-query-not-returning-expected-documents/368630/1 "2024-10-10T12:44:55Z")

</div>

**Summary**

GeoShape Polygon Query not returning expected documents that suspect are within the polygon; but am aware it maybe related to crossing the International Date Line.

My environment details below

**Kibana version** : 8.14.3

**Elasticsearch version:** 8.14.3

**Server OS version:** Windows 11 Enterprise

**Steps to reproduce:**

1. Index a document with a geopoint property that is within the UK, in my case I have

```auto
"metadata": {
    "mapLocations": [
        {
            "lon": -1.865,
            "lat": 53.811
        }
    ]
}

```

with the following mapping:

```auto
"metadata": {
    ...,
    "mapLocations": {
        "type": "geo_point"
     }
}

```

1. Query the index in kibana with the following query that uses geo\_shape of type polygon with counter clockwise coordinates from geoJSON object with the intersect relation

```auto
GET test_index/_search
{
  "query": {
    "geo_shape": {
      "metadata.mapLocations": {
        "shape": {
          "type": "Polygon",
          "orientation": "RIGHT",
          "coordinates": [
            [
              [
                -283.359375,
                -87.599705
              ],
              [
                984.375,
                -87.599705
              ],
              [
                984.375,
                86.574207
              ],
              [
                -283.359375,
                86.574207
              ],
              [
                -283.359375,
                -87.599705
              ]
            ]
          ]
        },
        "relation": "intersects"
      }
    }
  }
}

```

**Expected behavior:** Although the rectangle shaped polygon has a large longitude range than -180 to 180 I still expect it to return the document as it is within the given range.

**Screenshots (if relevant):** There is nothing to show as I get no hits but if I input the above geoJSON into the Analytics \> Map within Kibana it seems to show the expected shape that overlaps longitudinally which makes me think it should find the document as it seems to suggest the shape is valid

 ![Image of polygon used in the query in Kibana map tool](https://us1.discourse-cdn.com/elastic/original/3X/9/4/94d6c344d2924f256f9687de63949f54295a4215.png)

---

<div class="post-metadata">

**Author:** ![Shaun1](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@Shaun1](https://discuss.elastic.co/u/Shaun1)\
**Post date:** [October 10, 2024, 12:46pm UTC](https://discuss.elastic.co/t/geoshape-polygon-query-not-returning-expected-documents/368630/2 "2024-10-10T12:46:07Z")

</div>

I suspected initially that the above issue might be the anti-meridian problem since it crossed the International Date Line but I have other polygons that also cross this line but the query seems to return the expected matches.

For example this query works as expected

```auto
GET test_index/_search
{
  "query": {
    "geo_shape": {
      "metadata.mapLocations": {
        "shape": {
          "type": "Polygon",
          "orientation": "RIGHT",
          "coordinates": [
            [
              [
                -200,
                -90
              ],
              [
                900,
                -90
              ],
              [
                900,
                90
              ],
              [
                -200,
                90
              ],
              [
                -200,
                -90
              ]
            ]
          ]
        },
        "relation": "intersects"
      }
    }
  }
}

```

Although I appreciate it could still be related to the IDL

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [October 11, 2024, 5:02pm UTC](https://discuss.elastic.co/t/geoshape-polygon-query-not-returning-expected-documents/368630/3 "2024-10-11T17:02:07Z")

</div>

I think you are displaying the geometry by uploading the geojson directly which is not normalizing the coordinates. In order to check how Elasticsearch is interpreting the geometry, the best thing is to index it:

```auto
PUT /test
{
  "mappings": {
    "dynamic": "strict",
    "properties": {
      "location": {
        "type": "geo_shape"
      }
    }
  }
}

POST test/_doc
{
  "location": {
    "type": "Polygon",
    "orientation": "RIGHT",
    "coordinates": [
      [
        [
          -283.359375,
          -87.599705
        ],
        [
          984.375,
          -87.599705
        ],
        [
          984.375,
          86.574207
        ],
        [
          -283.359375,
          86.574207
        ],
        [
          -283.359375,
          -87.599705
        ]
      ]
    ]
  }
}

```

Then you can use the maps application inside kibana and the documents layer to look at the geometry:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/4/247557b5f8a526a110be457729442deb6bcb1137.jpeg)
