2015-05-09 49 views
4

我试图将范围索引添加到Azure DocumentDB集合中的特定属性,如this文章中所述。当执行我的代码来创建集合我得到以下错误:将范围索引添加到Azure DocumentDB集合时出现异常

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

我使用创建集合的代码是:

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); 

代码工作,如果我设置的路径该索引简单地为“/”,但我更愿意能够在特定属性上创建索引。我究竟做错了什么?

回答

5

你必须包括“/”像一个额外的IncludedPath:

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); 

另外,如果你想从索引中完全排除所有其他路径,你可以做到以下几点:

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始终要求您包含或排除“/”,以便索引方案明确无误。希望这可以帮助。

+0

最近发布的版本有这个改变吗?我无法使用IndexingPath或IndexType,因为它们被列为“内部”。我能够使用IncludePath类来完成此操作。 –

+0

是的,最近这个语法已经改变了。 –

相关问题