Geohex_grid aggregation in opensearch throws error

I’m getting this error when trying “geohex_grid” aggregation in java opensearch api.

"aggs": {
"filter_agg": {
  "filter": {
    "geo_bounding_box": {
      "ignore_unmapped": true,
      "location": {
        "top_left": {
          "lat": 90,
          "lon": -180
        },
        "bottom_right": {
          "lat": -90,
          "lon": 180
        }
      }
    }
  },
  "aggs": {
    "2": {
      "geohex_grid": {
        "field": "location",
        "precision": 2
      },
      "aggs": {
        "3": {
          "geo_centroid": {
            "field": "location"
          }
        }
      }
    }
  }
}

So when trying this query, I’m getting this error:

"Unknown aggregation type [geohex_grid]"