2011-09-26 96 views
1

SSSI目前已呼籲SchoolMetrics其聚集在校場爲重點的幾個領域,併產生的文件這樣的索引上嵌套屬性:RavenDB指數查詢

{ 
    School: { 
     SchoolId: 1234 
     Name: "asdf" 
    } 
    StudentCount: 1234, 
    CourseCount: 1234 
} 

我的指數圖的定義爲:

from s in docs.Metrics 
where s.School != null 
select new 
{ 
    s.School, 
    s.StudentCount, 
    s.CourseCount 
} 

而且減少是:

from s in results 
group s by s.School 
into g 
select new 
{ 
    School= g.Key, 
    StudentCount = g.Sum(x => x.StudentCount), 
    CourseCount = g.Sum(x => x.CourseCount) 
} 

當我嘗試做一個查詢這樣的答: http://localhost:8080/databases/Database/indexes/SchoolMetrics?query=School.SchoolId:1234

它給我這個錯誤:

"System.ArgumentException: The field 'School.SchoolId' is not indexed, cannot query on fields that are not indexed 
    at Raven.Database.Indexing.Index.IndexQueryOperation.AssertQueryDoesNotContainFieldsThatAreNotIndexes() in c:\Builds\raven\Raven.Database\Indexing\Index.cs:line 639 
    at Raven.Database.Indexing.Index.IndexQueryOperation.<Query>d__24.MoveNext() in c:\Builds\raven\Raven.Database\Indexing\Index.cs:line 558 
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() 
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() 
    at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection) 
    at Raven.Database.DocumentDatabase.<>c__DisplayClass70.<Query>b__68(IStorageActionsAccessor actions) in c:\Builds\raven\Raven.Database\DocumentDatabase.cs:line 705 
    at Raven.Storage.Esent.TransactionalStorage.ExecuteBatch(Action`1 action) in c:\Builds\raven\Raven.Storage.Esent\TransactionalStorage.cs:line 378 
    at Raven.Storage.Esent.TransactionalStorage.Batch(Action`1 action) in c:\Builds\raven\Raven.Storage.Esent\TransactionalStorage.cs:line 341 
    at Raven.Database.DocumentDatabase.Query(String index, IndexQuery query) in c:\Builds\raven\Raven.Database\DocumentDatabase.cs:line 652 
    at Raven.Database.Server.Responders.Index.PerformQueryAgainstExistingIndex(IHttpContext context, String index, IndexQuery indexQuery, Guid& indexEtag) in c:\Builds\raven\Raven.Database\Server\Responders\Index.cs:line 150 
    at Raven.Database.Server.Responders.Index.ExecuteQuery(IHttpContext context, String index, Guid& indexEtag) in c:\Builds\raven\Raven.Database\Server\Responders\Index.cs:line 136 
    at Raven.Database.Server.Responders.Index.GetIndexQueryRessult(IHttpContext context, String index) in c:\Builds\raven\Raven.Database\Server\Responders\Index.cs:line 92 
    at Raven.Database.Server.Responders.Index.OnGet(IHttpContext context, String index) in c:\Builds\raven\Raven.Database\Server\Responders\Index.cs:line 84 
    at Raven.Database.Server.Responders.Index.Respond(IHttpContext context) in c:\Builds\raven\Raven.Database\Server\Responders\Index.cs:line 46 
    at Raven.Http.HttpServer.DispatchRequest(IHttpContext ctx) in c:\Builds\raven\Raven.Http\HttpServer.cs:line 399 
    at Raven.Http.HttpServer.HandleActualRequest(IHttpContext ctx) in c:\Builds\raven\Raven.Http\HttpServer.cs:line 222" 

什麼離奇的是,當我嘗試查詢的StudentCount或它的工作原理CourseCount場......我已經試過在學校加入分析儀.SchoolId字段,但似乎並沒有幫助...我也嘗試弄平結果文件,並得到同樣的錯誤。我錯過了什麼嗎?

回答

3

除了托馬斯的筆記,你必須明白,我們正在查看索引的最終輸出作爲索引項目。 如果您正在索引一個複雜的對象,它將被索引爲Json值,而不是您可以進一步查詢的內容。

+0

因此,RavenDB中是否有任何選項可以同時過濾存儲在嵌套集合中的複雜對象的多個屬性,而無需扇出索引?我描述我的情況[這裏](http://stackoverflow.com/questions/42030294/ravendb-indexing-and-querying-complex-hierarhical-data-nested-properties),請協助,如果可以的話。 –

2

您正在按學校對象分組。如何平展指數?

from s in docs.Metrics 
where s.School != null 
select new 
{ 
    SchoolId = s.School.SchoolId, 
    s.StudentCount, 
    s.CourseCount 
} 

from s in results 
group s by s.SchoolId 
into g 
select new 
{ 
    SchoolId = g.Key, 
    StudentCount = g.Sum(x => x.StudentCount), 
    CourseCount = g.Sum(x => x.CourseCount) 
}