2015-05-09 42 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

是的,最近這個語法已經改變了。 –

相關問題