Geo-bounding box query returns results outside of the box

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?

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
						}
					}
				}
			}
		}
	}
}

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:

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.

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