Reputation: 828
I'm working width Azure CosmosDB (SQL API) and I'm trying to execute some geospatial queries using Microsoft.Azure.Cosmos.Spatial.
For example I would like to Take the fifth closest items. So I tried :
var query = Collection.GetItemLinqQueryable<T>();
var items = query.OrderBy(i => i.Location.Distance(myCenterPoint)).Take(5);
But I get the following exception : Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException: {"errors":[{"severity":"Error","message":"Unsupported ORDER BY clause. ORDER BY item expression could not be mapped to a document path."}]}
So I tried something like :
var items = query.Where(i => i.Location.Distance(myCenterPoint) < 5000).ToList();
var newItems = items.OrderBy(i => i.Location.Distance(myCenterPoint)).ToList();
But I get an other exception telling me that Distance methode can only execute in CosmosDb.
The only option I see is to create my own Distance method, then I'll be able to Order my collection. But I have the 5000m limit. If there are only 3 items within the 5000m, I will need to perform an other query with an increased limit. But I have the feeling this is not optimized.
Have you any suggestions ?
Upvotes: 0
Views: 678
Reputation: 8763
Unfortunately ORDER BY on ST_DISTANCE is not supported today. This is on the roadmap to eventually do. You can track that feature request on User Voice.
Thanks.
Upvotes: 1