geolocation - ElasticSearch, filter locations where either longitude or latitude should be larger than 0 -


what try achieve aggregation of geo_bounds. however, in test database got strange values location might negative (this isn't per strange) doesn't make sense in case.

for queries, might result in bounding box covers country not expecting.

i filter geo_bounds aggregation either longitude or latitude must larger 0.

i know there filter aggregations, specified on https://www.elastic.co/guide/en/elasticsearch/reference/1.6/search-aggregations-bucket-filter-aggregation.html not sure how range check longitude or latitude.

in our index model got structure have location object contains lon , lat.

as negative values valid location, they're treated valid es. so, 2 options here: validate data during indexing (way better imo, seems late in case) or filtering out points negative location values in query.

the problem on-the-fly filtering es can filter geo-points 4 filters only. , filters not cheap in terms of performance. can use geo_bounding_box need, this:

index:

put so/_mapping/t1 {   "t1": {     "properties": {       "pin": {         "properties": {           "location": {             "type": "geo_point"           }         }       }     }   } } post so/t1 {   "pin": {     "location": {       "lat": 10.1,       "lon": 9.9     }   } } post so/t1 {   "pin": {     "location": {       "lat": 20.1,       "lon": 99.9     }   } } post so/t1 {   "pin": {     "location": {       "lat": -10.1,       "lon": -9.9     }   } } 

query:

get so/t1/_search?search_type=count {   "aggs": {     "plain": {       "geo_bounds": {         "field": "pin.location"       }     },     "positive": {       "filter": {         "geo_bounding_box": {           "pin.location": {             "top_left": {               "lat": 90,               "lon": 0             },             "bottom_right": {               "lat": 0,               "lon": 180             }           }         }       },       "aggs": {         "bounds": {           "geo_bounds": {             "field": "pin.location"           }         }       }     }   } } 

result:

{    "took": 3,    "timed_out": false,    "_shards": {       "total": 5,       "successful": 5,       "failed": 0    },    "hits": {       "total": 3,       "max_score": 0,       "hits": []    },    "aggregations": {       "positive": {          "doc_count": 2,          "bounds": {             "bounds": {                "top_left": {                   "lat": 20.1,                   "lon": 9.9                },                "bottom_right": {                   "lat": 10.1,                   "lon": 99.9                }             }          }       },       "plain": {          "bounds": {             "top_left": {                "lat": 20.1,                "lon": -9.9             },             "bottom_right": {                "lat": -10.1,                "lon": 99.9             }          }       }    } } 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -