Ok, so the CosmosDb Collection has it's index policy set to consistent, automatic, has the default hash and range indexes AND we added a path to our own timestamp properties in order to sort by them.
I know the paths are correct, since I'm not able to order by them UNLESS I have them set. But:
When sorting by Cosmos built-in property _ts - the cost for an OrderBy query is like 20 RU/s. That's great. Now, when sorting by our OWN timestamp columns (we have two where one is a string timestamp, and the other is Unixbased number just as the built-in _ts column. This query costs 400 RU/s !???
Putting the new indexing rules enable us to query and order it, but the RUs are insane. Why is this and how do we address it?
I know that you couldn't change the indexing policy Ad Hoc earlier, but this has been addressed according to Microsoft.
EDIT: It is a simple collection, no partitioning is configured, and the query runs against this only collection, selects only one document (top 1).
SELECT top 1 * FROM c WHERE c.AllCompleted = true ORDER BY c.EndFetchDateTimeUtcUnix DESC
vs
SELECT top 1 * FROM c WHERE c.AllCompleted = true ORDER BY c._ts DESC
The Index looking like this:
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/",
"indexes": [
{
"kind": "Hash",
"dataType": "Number",
"precision": 3
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
},
{
"path": "/EndFetchDateTimeUtcUnix/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
],
"excludedPaths": []
}