CaaS and Geospatial-Index
Author: MBischof
Publication Date: 3/4/2022 10:06
Hello community,
has anybody experience in generating and using a geospatial-index inside of the CaaS and want to share?
Usecase:
We store the data (address, opening times, location, latitude, longitude,...) of our branch-offices inside the Caas and our mobile app consumes the data. Now there should be some kind of proximity search to get the next X offices around my current location.
We expanded our data and stored a GeoJson-Object additionally, but now the big question is, how to generate the geospatial-index. Helpdesk says, basically the Rest-Api leverages MongoDB's geospatial support but we have currently no Idea, how to start generating the index.
Any ideas to that out there ?
Thanks in advance for any suggestion,
Best regards,
Marco
Tags: caas
-
Author: NMc - 3/7/2022 14:30
In general an index in the Rest API can be created by following this documentation:You can read how a geospatial index would look like here: https://docs.mongodb.com/manual/geospatial-queries/#geospatial-indexesAn example Request could look like this:curl --location --request PUT 'https://${customer}-${stage}caas-api.e-spirit.cloud/${tenant-id}/${project-uuid}.preview.content/_indexes/my-geospatial-index' \--header 'authorization: apikey="*****************"' \--header 'Content-Type: application/json' \--data-raw '{"keys": {"2dsphere": 1}}'Kind regards,
Nico
0 -
Author: groth - 3/22/2022 16:44
Hi ,
did the answer from help? If not I might suggest a slightly different payload for the curl request:
curl --location --request PUT 'https://${customer}-${stage}caas-api.e-spirit.cloud/${tenant-id}/${project-uuid}.preview.content/_indexes/my-geospatial-index' \ --header 'authorization: apikey="*****************"' \ --header 'Content-Type: application/json' \ --data-raw '{ "keys": { "<fieldname>": "2dsphere" } }'Based on these resources:
- https://restheart.org/docs/v4/mgmt/indexes/#example---create-a-text-index-on-property-item (not using text as index type, but 2dsphere)
- https://docs.mongodb.com/manual/geospatial-queries/#2dsphere
Would love to get some feedback if your issue could be solved.
Best regards, Chris
0 -
Author: MBischof - 3/23/2022 9:00
HI ,
thanks for your reply. Based on your suggestions we found a working solution for us.
The basic things like the data-structure (Geo-Json Object) were correct before, the missing thing was to use a PUT-Statement to create the index over the correct field. Once this was done, getting the correct data with a $near-Operator was easy...
So again thanks for you help and best regards,
Marco
0
Please sign in to leave a comment.
Comments
3 comments