Here is a sample document that we would like to store:
{
"name": "Joe Bloggs",
"locations": [
{ "type": "Point", "coordinates": [1,1] },
{ "type": "Point", "coordinates": [2,2] }
]
}
The key feature of the document is that the "locations" property is an array of GeoJSON points.
According to the documentation it is possible to define an indexing policy for the locations array.
However, it's not clear whether spatial queries such as ST_WITHIN
can be used to search, for example, whether any of the points in the array fall within a certain radius of a specified point.
My question: Does CosmosDB support indexing and querying of spatial data when stored in an array?
From private conversation with CosmosDB:
Can it be indexed?
yes, you just need to index /locations/[]/? or /locations/*
Can it be queried?
yes, you can query over an array of points by using a JOIN to unwind the array.
SELECT * FROM c JOIN loc IN c.locations WHERE ST_DISTANCE(loc, @myLocation) < @distance
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With