sssI目前有一个名为SchoolMetrics的索引,它将学校字段中的几个字段聚合为关键字并生成如下文档:
{
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字段时,它的工作原理是什么......我尝试在School.SchoolId字段上添加一个分析器,但这似乎没有帮助......我也是试图弄平出结果文件,我得到同样的错误。我错过了什么吗?
答案 0 :(得分:3)
除了托马斯的说明之外,您必须了解我们正在查看索引的最终输出作为索引项。 如果要索引复杂对象,它将被编入索引为Json值,而不是您可以进一步查询的内容。
答案 1 :(得分: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)
}