-
Notifications
You must be signed in to change notification settings - Fork 0
Geo Queries
Sidhant Aggarwal edited this page Aug 9, 2020
·
3 revisions
Cerebro Supports the following types of Geo Queries:
- Around Center Query
- Bounding Box Query
In this query type, you basically index a geo-point of points in documents. For this, there is a reserved key _geo_location
. An example of a document having a geo-point is:
{
"document": {
"_geo_location": {
"lon": 76.7891857,
"lat": 30.7356786
},
"address": {
"pincode": 160019,
"house_number": "232"
},
"name": "sidhant aggarwal",
"numbers": [
12,
14
],
"age": 54,
"tags": [
"first",
"second"
]
}
}
_geo_location
can be an array as well to support multiple geo-points
{
"document": {
"_geo_location": [
{
"lon": 76.7891857,
"lat": 30.7356786
},
{
"lon": 76.7891857,
"lat": 30.7356786
}
],
"address": {
"pincode": 160019,
"house_number": "232"
},
"name": "sidhant aggarwal",
"numbers": [
12,
14
],
"age": 54,
"tags": [
"first",
"second"
]
}
}
Now once the data is indexed we can issue geo-queries. The same search API is used for this. Following are the parameters needed:
- geo_query_type (
AROUND_RADIUS
) - max_radius (in meters)
- center_point
curl --location --request POST 'http://localhost:9998/v1/index/users/search' \
--header 'Content-Type: application/json' \
--data-raw '{
"geo_query_type": "BOUNDING_BOX",
"max_radius": 1000,
"center_point": {
"lat": 28.6471948,
"lon": 76.9531794
}
}'
Indexing document is the same as above
curl --location --request POST 'http://localhost:9998/v1/index/users/search' \
--header 'Content-Type: application/json' \
--data-raw '{
"geo_query_type": "BOUNDING_BOX",
"bounding_box": {
"top_left_lat": 30.712724,
"top_left_lon": 76.805697,
"bottom_right_lat": 30.692480,
"bottom_right_lon": 76.855554
}
}'
Along with these the previously mentioned params are supported as well such as filters, query etc.