1

I have following mapping in my elasticsearch:

{
  "mappings": {
    "event": {
      "_all":       { "enabled": false  },
      "properties": {
        "type":     { "type": "string", "index": "not_analyzed"},
        "id":  { "type": "string"},
        "location": { "type": "geo_point"}
      }
    }
  }
} 

What I want to do is query for all records that are localized inside map area defined by single geohash. I am aware of geohash cell query which would work perfectly in my example, but unfortunatelly require geo_point field to be indexed in with geohash_prefix option set to true which is deprecated in elasticearch 2.4.

What is the correct way to do that in latest elasticsearch version? I can't find it anywhere in the documentation.

Liplttaa
  • 11
  • 2

2 Answers2

1

Elasticsearch 6.0.0-alpha2 documentation says the following:

The geohash_cell query has been removed. Instead use the Geo Bounding Box Query

Try to specify the bottom_left bounding box argument as your_geohash_prefix + '00...0' and the top_right as your_geohash_prefix + 'zz...z'. You should append as much 0 and z symbols to your geohash prefix to make it of length 12 (max precision geohash length).

E.g. for geohash prefix dr5r9 it would look like:

{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_bounding_box" : {
                    "coordinates" : {
                        "bottom_left" : "dr5r90000000",
                        "top_right" : "dr5r9zzzzzzz"
                    }
                }
            }
        }
    }
}

0 and z where taken as geohash grid's bottom left and top right corners respectively.

I succeeded with this approach testing it by comparing matched documents counts with the geohash grid aggregation result of corresponding precision. But still I had some cases that some points had not fallen into such bounding box. Can not say it is 100% correct method.

Sergii Golubev
  • 398
  • 3
  • 11
0

To get all points try to add 0 and z as in Sergii's answer but than decode and use geo_bounding_box query with top, left, bottom, right.

dr5r90000000 -> longitude: -74.13574202, latitude: 40.69335946

dr5r90zzzzzz -> longitude: -74.12475603, latitude: 40.69885246

{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_bounding_box" : {
                    "coordinates" : {
                        "top": 40.69885246,
                        "left": -74.13574202,
                        "bottom": 40.69335946,
                        "right": -74.12475603,
                    }
                }
            }
        }
    }
}