0

I'm using Elasticsearch 5.1 with geohash_grid query as below:

{
  "query": {
    ...
    "geo_bounding_box":...
  },
  "aggs": {
    "lochash": {
      "geohash_grid": {
        "field": "currentShopGeo",
        "precision": 5
      }
    }
  }
}

And here is the results of elasticsearch:

{
  ....,
  "aggregations": {
    "lochash": {
      "buckets": [
        {
          "key": "w3gvv",
          "doc_count": 1  // only 1 doc_count
        }
      ]
    }
  }
}

Then, I used "w3gvv" to decode geohash and have a bounding box as below following "w3gvv".

{
  "top_left": {
    "lat": 10.8984375,
    "lon": 106.7431640625
  },
  "bottom_right": {
    "lat": 10.8544921875,
    "lon": 106.787109375
  }
}

However, when I use the returned bounding box above to search for the document inside, it appears that Elasticsearch returns 13 items more. Anyone have any idea why it is so weird?

  • Can you also show the query at the top, specially the `geo_bounding_box` one? – Val May 27 '17 at 04:38
  • `{ "query": { "bool": { "should": [ { "geo_bounding_box": { "type": "indexed", "currentShopGeo": { "top_left": { "lat": 10.8651173923467, "lon": 106.591202952246 }, "bottom_right": { "lat": 10.7605769974159, "lon": 106.791360117773 } } } } ] } }, "aggs": { ... } }` => { "key": "w3gvv", "doc_count": 1} – Le Huu HoangGia May 27 '17 at 04:58

1 Answers1

1

Got a solution, We could use geo_bounds to know the exact boundary of the clusters that are returned by Elasticsearch as below:

"aggs": {
  "lochash": {
    "geohash_grid": {
      "field": "currentShopGeo",
      "precision": 5
    },
    "aggs": {
      "cell": {
        "geo_bounds": {
          "field": "currentShopGeo"
        }
      }
    }
  }
}

The result should be:

{
   "key": "w3gvv",
   "doc_count": 1,
   "cell": {
     "bounds": {
       "top_left": {
          "lat": 10.860191588290036,
          "lon": 106.75263083539903
       },
       "bottom_right": {
          "lat": 10.860191588290036,
          "lon": 106.75263083539903
       }
     }
  }
 }

It appears that the results shows exactly where the item is.