在RavenDb中,我有一个简单的多图索引,如下所示:
public class MessageOutboxIndex : AbstractMultiMapIndexCreationTask<MessageOutboxIndex.ReduceResult>
{
public class ReduceResult
{
public string Id { get; set; }
public string FromAccountId { get; set; }
public Core.Enums.Message.MessageStatus OutboxStatus { get; set; }
public string ToAccountId { get; set; }
public string ToArtistName { get; set; }
public DateTimeOffset DateSent { get; set; }
public string Subject { get; set; }
}
public MessageOutboxIndex()
{
AddMap<Message>(messages => from msg in messages
select new
{
Id = msg.Id,
FromAccountId = msg.FromAccountId,
OutboxStatus = msg.OutboxStatus,
ToAccountId = (string)null,
ToArtistName = (string)null,
DateSent = msg.DateSent,
Subject = msg.Subject
});
AddMap<MessageRecipient>(recipients => from recipient in recipients
select new
{
Id = recipient.MessageId,
FromAccountId = (string)null,
OutboxStatus = (object)null,
ToAccountId = recipient.ToAccountId,
ToArtistName = recipient.ToArtistName,
DateSent = DateTimeOffset.MinValue,
Subject = (string)null
});
Reduce = results => from result in results
group result by result.Id
into g
select new
{
Id = g.Key,
FromAccountId = g.Select(x => x.FromAccountId).Where(x => x != null).FirstOrDefault(),
OutboxStatus = g.Select(x => x.OutboxStatus).Where(x => x != null).FirstOrDefault(),
ToAccountId = g.Select(x => x.ToAccountId).Where(x => x != null).FirstOrDefault(),
ToArtistName = g.Select(x => x.ToArtistName).Where(x => x != null).FirstOrDefault(),
DateSent = g.Max(x => (DateTimeOffset)x.DateSent),
Subject = g.Select(x => x.Subject).Where(x => x != null).FirstOrDefault()
};
}
}
但是,我现在只想使用以下示例查询从Id返回此索引中的特定消息:
var messages = _documentSession.Query<MessageOutboxIndex.ReduceResult, MessageOutboxIndex>()
.Where(x => x.Id.In(new string[2] {"messages/1", "messages/2"}))
.ToList();
此操作失败,并显示以下错误:
System.ArgumentException: The field '__document_id' is not indexed, cannot query on fields that are not indexed
通过Id查询适用于普通索引,但不适用于多图索引。这是一个错误吗?
保
答案 0 :(得分:2)
保罗 我们自动将Id字段转换为__document_id,因为我们不知道我们正在查询没有__document_id的m / r索引。 你的解决方法是要走的路,是的。