# Geo-bounding box query returns results outside of the box

**URL:** <https://discuss.elastic.co/t/geo-bounding-box-query-returns-results-outside-of-the-box/310618>\
**Category:** Elasticsearch\
**Created:** [July 26, 2022, 9:55am UTC](https://discuss.elastic.co/t/geo-bounding-box-query-returns-results-outside-of-the-box/310618 "2022-07-26T09:55:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xinyuluo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xinyuluo/32/108850_2.png) [@xinyuluo](https://discuss.elastic.co/u/xinyuluo)\
**Post date:** [July 26, 2022, 9:55am UTC](https://discuss.elastic.co/t/geo-bounding-box-query-returns-results-outside-of-the-box/310618/1 "2022-07-26T09:55:37Z")

</div>

Hi! I am new to this space. I was trying to use `geo-bounding box` feature to match geo\_points inside a bounding box, but it seems that my query always generates returns outside of the box. for instance, the following query returns some result at "lat": 1.307245 and "lon": -51.0744611, which is obviously outside of box (longitude was wrong). I wonder what am I missing in this case?

```auto
GET my_index/_search
{
	"query": {
		"bool": {
			"must": {
			  "match_all": {}
			},
			"filter": {
				"geo_bounding_box": {
					"coordinate": {
						"top_left": {
							"lat": 1.3073336,
							"lon": 103.8684735
					  },
					  "bottom_right": {
							"lat": 1.3051584,
							"lon": 103.8535414
						}
					}
				}
			}
		}
	}
}

```

---

<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:** [July 26, 2022, 10:29am UTC](https://discuss.elastic.co/t/geo-bounding-box-query-returns-results-outside-of-the-box/310618/2 "2022-07-26T10:29:37Z")

</div>

Hi @xinyuluo,

Welcome to the community!

Your query defines a left latitude of 103.8684735 and a right latitude that is 103.8535414 so left \> right. In that case your bounding box goes across the dateline. We can rewrite your query as:

```auto
GET my_index/_search
{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "should": [
        {
          "geo_bounding_box": {
            "coordinate": {
              "top_left": {
                "lat": 1.3073336,
                "lon": 103.8684735
              },
              "bottom_right": {
                "lat": 1.3051584,
                "lon": 180
              }
            }
          }
        },
        {
          "geo_bounding_box": {
            "coordinate": {
              "top_left": {
                "lat": 1.3073336,
                "lon": -180
              },
              "bottom_right": {
                "lat": 1.3051584,
                "lon": 103.8535414
              }
            }
          }
        }
      ]
    }
  }
}

```

Hope it makes sense.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 23, 2022, 10:29am UTC](https://discuss.elastic.co/t/geo-bounding-box-query-returns-results-outside-of-the-box/310618/3 "2022-08-23T10:29:48Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
