RavenDB 嵌套属性索引查询
sss我目前有一个名为 SchoolMetrics 的索引,它聚合了 School 字段上的多个字段作为键并生成如下文档:
{
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 字段上添加分析器,但这似乎没有帮助...我也尝试压平生成的文档,但出现了相同的错误。我错过了什么吗?
sssI currently have an index called SchoolMetrics that aggregates several fields on the School field as the key and produces documents like this:
{
School: {
SchoolId: 1234
Name: "asdf"
}
StudentCount: 1234,
CourseCount: 1234
}
My index map is defined as:
from s in docs.Metrics
where s.School != null
select new
{
s.School,
s.StudentCount,
s.CourseCount
}
And the reduce is:
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)
}
When I try to do a query such a:
http://localhost:8080/databases/Database/indexes/SchoolMetrics?query=School.SchoolId:1234
It gives me this error:
"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"
What's weirder is that when I try querying on the StudentCount or CourseCount fields it works... I've tried adding an analyzer on the School.SchoolId field but that doesn't seem to help... I've also tried flattening out the resulting document and I get the same error. Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了托马斯的注释之外,您还必须了解我们正在将索引的最终输出视为索引项。
如果您正在为一个复杂的对象建立索引,它将被索引为 Json 值,而不是您可以进一步查询的内容。
In addition to Thomas' note, you have to understand that we are looking at the final output from the index as the indexed item.
And if you are indexing a complex object, it is going to be indexed as a Json value, not as something that you can query on further.
您正在按 School 对象进行分组。指数扁平化怎么样?
You are grouping by the School object. How about flattening the index?