6

I'm trying to add a range index to a specific property in an Azure DocumentDB collection as described in this article. When my code to create the collection is executed I get the following error:

The special mandatory indexing path \\"\/\\" is not provided in any of the path type sets. Please provide this path in one of the sets.

The code I'm using to create the collection is:

var collection = new DocumentCollection { id = "myCollectionID" };

collection.IndexingPolicy.IncludedPaths.Add(new IndexingPath
{
    IndexType = IndexType.Range,
    Path = "/\"TimeStamp\"/\"Epoch\"/?",
    NumericPrecision = 7
});

this._client.CreateDocumentCollectionAsync(database.SelfLink, collection);

The code works if I set the path of the index to simply "/", but I'd prefer to be able to create the index on specific properties. What am I doing wrong?

1 Answer 1

9

You have to include "/" as an additional IncludedPath like:

var collection = new DocumentCollection { id = "myCollectionID" };

collection.IndexingPolicy.IncludedPaths.Add(new IndexingPath
{
    IndexType = IndexType.Range,
    Path = "/\"TimeStamp\"/\"Epoch\"/?",
    NumericPrecision = 7
});

collection.IndexingPolicy.IncludedPaths.Add(new IndexingPath
{
    IndexType = IndexType.Hash,
    Path = "/"
});

this._client.CreateDocumentCollectionAsync(database.SelfLink, collection);

Alternatively, if you want to exclude every other path completely from indexing, you can do the following:

var collection = new DocumentCollection { id = "myCollectionID" };

collection.IndexingPolicy.IncludedPaths.Add(new IndexingPath
{
    IndexType = IndexType.Range,
    Path = "/\"TimeStamp\"/\"Epoch\"/?",
    NumericPrecision = 7
});

collection.IndexingPolicy.ExcludedPaths.Add("/");

this._client.CreateDocumentCollectionAsync(database.SelfLink, collection);

DocumentDB always requires you to either include or exclude "/", so that the indexing scheme is unambiguous. Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Has this changed in recent releases? I was unable to use IndexingPath or IndexType due to them being listed as "internal". I was able to do this using the IncludePath class.
Yes, the syntax of this has changed recently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.