I am trying to exclude
all and include
only certain indexes on a collection in CosmosDb.
Here is my code:
// A property in the class...
public override IEnumerable<IncludedPath> CollectionIndexes => new List<IncludedPath>
{
new IncludedPath{ Path= "/\"CreatedOnUtc\"" }, // I have tried "/CreatedOnUtc" as well
// few more indexes...
};
// Code in the CreateCollection method...
collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/*" }); // I have tried the code without this line as well
foreach (var path in CollectionIndexes) // Add indexes over certain properties only.
{
collection.IndexingPolicy.IncludedPaths.Add(path);
}
When I run the code, I get this very exception ever single time:
Message: {"Errors":["The indexing path '/\"CreatedOnUtc\"' could not be accepted, failed near position '5'. Please ensure that the path is a valid path. Common errors include invalid characters or absence of quotes around labels."]} ActivityId: 2627fe24-64a0-46b3-bf9a-13cb160c17a7, Request URI: /apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.22.0.0, documentdb-dotnet-sdk/1.22.0 Host/64-bit MicrosoftWindowsNT/10.0.16299.0
When I change the path to "/CreatedOnUtc"
, I still get to see the same message:
Message: {"Errors":["The indexing path '/CreatedOnUtc' could not be accepted, failed near position '3'. Please ensure that the path is a valid path. Common errors include invalid characters or absence of quotes around labels."]} ActivityId: 30dc7429-df87-4080-912e-60aa731ae809, Request URI: /apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.22.0.0, documentdb-dotnet-sdk/1.22.0 Host/64-bit MicrosoftWindowsNT/10.0.16299.0
What am I missing out on? It seems to be something very basic but I have wasted 24 hours on this trying out various combinations!
I am using the C# Sql API to do so. I am trying this out on the CosmosDb Emulator
on my local PC.
"/\"id\""
and not simply"/id"
? – Nick Chapsas"/id"
as well.. – bitIndexes = new Collection<Index> { new RangeIndex(DataType.String) { Precision = 20 } } });
– Nick ChapsasCreatedOnUtc
should be/CreatedOnUtc/?
– Nick Chapsas