elasticsearchelastic-stackgeohashing

Elasticsearch how to use geohex_grid or geohash_grid return a full detail (or at lease get full detail when doc_count:1)


Elasticsearch how to use geohex_grid or geohash_grid return a full detail (or at lease get full detail when doc_count:1)

I have used elasticsearch geohex but what I can get is "key" and "doc_count" Is there a way to get full detail (or in case doc_count = 1)

belove is an example request:

POST vt_data_warehouse/_search?size=0
{
  "aggregations": {
    "tiles_in_bounds": {
      "geohash_grid": {
        "field": "position",
        "precision": 6,
        "bounds": {
          "top_left": "POINT (104.731344 11.541166)",
          "bottom_right": "POINT (104.89368038286129 11.464655721322128)"
        }
      }
    }
  }
}

and this is the result:

"aggregations": {
    "tiles_in_bounds": {
      "buckets": [
        {
          "key": "",
          "doc_count": 32
        },
        {
          "key": "",
          "doc_count": 30
        },
        {
          "key": "",
          "doc_count": 21
        },
        {
          "key": "",
          "doc_count": 8
        },
        {
          "key": "",
          "doc_count": 7
        },
        {
          "key": "",
          "doc_count": 2
        },
        {
          "key": "",
          "doc_count": 1
        },
        {
          "key": "",
          "doc_count": 1
        },
        {
          "key": "",
          "doc_count": 1
        },
        {
          "key": "",
          "doc_count": 1
        },
        {
          "key": "",
          "doc_count": 1
        }
      ]
    }

Solution

  • In order to show the documents in each bucket, you can simply add a top_hits sub-aggregation, like this:

    POST vt_data_warehouse/_search?size=0
    {
      "aggregations": {
        "tiles_in_bounds": {
          "geohash_grid": {
            "field": "position",
            "precision": 6,
            "bounds": {
              "top_left": "POINT (104.731344 11.541166)",
              "bottom_right": "POINT (104.89368038286129 11.464655721322128)"
            }
          },
          "aggs": {
            "details": {
              "top_hits": {
                "size": 50
              }
            }
          }
        }
      }
    }