Query multimap index by Id - The field '__document_id' is not indexed, cannot query on fields that are not indexed

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-16 03:49:25

问题


In RavenDb I have a simple multimap index which looks like below:

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()
                                    };

        }
    } 

However, I now want to only return specific messages from this index by Id using this example query below:

var messages = _documentSession.Query<MessageOutboxIndex.ReduceResult, MessageOutboxIndex>()
                .Where(x => x.Id.In(new string[2] {"messages/1", "messages/2"}))
                .ToList();

This fails with the following error:

System.ArgumentException: The field '__document_id' is not indexed, cannot query on fields that are not indexed

Querying by Id works for normal indexes, but not multimap indexes. Is this a bug?

Paul


回答1:


Paul, We auto translate the Id field to the __document_id, because we don't know that we are querying a m/r index that doesn't have a __document_id. Your workaround is the way to go, yes.



来源:https://stackoverflow.com/questions/9115328/query-multimap-index-by-id-the-field-document-id-is-not-indexed-cannot-qu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!