Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 3.78 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Query multimap index by Id - The field '__document_id' is not indexed, cannot query on fields that are not indexed
  2. public class MessageOutboxIndex : AbstractMultiMapIndexCreationTask<MessageOutboxIndex.ReduceResult>
  3.     {
  4.         public class ReduceResult
  5.         {
  6.             public string Id { get; set; }
  7.             public string FromAccountId { get; set; }
  8.             public Core.Enums.Message.MessageStatus OutboxStatus { get; set; }
  9.             public string ToAccountId { get; set; }
  10.             public string ToArtistName { get; set; }
  11.             public DateTimeOffset DateSent { get; set; }
  12.             public string Subject { get; set; }
  13.         }
  14.  
  15.         public MessageOutboxIndex()
  16.         {
  17.             AddMap<Message>(messages => from msg in messages
  18.                                         select new
  19.                                                    {
  20.                                                        Id = msg.Id,
  21.                                                        FromAccountId = msg.FromAccountId,
  22.                                                        OutboxStatus = msg.OutboxStatus,
  23.                                                        ToAccountId = (string)null,
  24.                                                        ToArtistName = (string)null,
  25.                                                        DateSent = msg.DateSent,
  26.                                                        Subject = msg.Subject
  27.                                                    });
  28.  
  29.             AddMap<MessageRecipient>(recipients => from recipient in recipients
  30.                                                        select new
  31.                                                                   {
  32.                                                                       Id = recipient.MessageId,
  33.                                                                       FromAccountId = (string)null,
  34.                                                                       OutboxStatus = (object)null,
  35.                                                                       ToAccountId = recipient.ToAccountId,
  36.                                                                       ToArtistName = recipient.ToArtistName,
  37.                                                                       DateSent = DateTimeOffset.MinValue,
  38.                                                                       Subject = (string)null
  39.                                                                   });
  40.  
  41.             Reduce = results => from result in results
  42.                                 group result by result.Id
  43.                                     into g
  44.                                     select new
  45.                                     {
  46.                                         Id = g.Key,
  47.                                         FromAccountId = g.Select(x => x.FromAccountId).Where(x => x != null).FirstOrDefault(),
  48.                                         OutboxStatus = g.Select(x => x.OutboxStatus).Where(x => x != null).FirstOrDefault(),
  49.                                         ToAccountId = g.Select(x => x.ToAccountId).Where(x => x != null).FirstOrDefault(),
  50.                                         ToArtistName = g.Select(x => x.ToArtistName).Where(x => x != null).FirstOrDefault(),
  51.                                         DateSent = g.Max(x => (DateTimeOffset)x.DateSent),
  52.                                         Subject = g.Select(x => x.Subject).Where(x => x != null).FirstOrDefault()
  53.                                     };
  54.  
  55.         }
  56.     }
  57.        
  58. var messages = _documentSession.Query<MessageOutboxIndex.ReduceResult, MessageOutboxIndex>()
  59.                 .Where(x => x.Id.In(new string[2] {"messages/1", "messages/2"}))
  60.                 .ToList();
  61.        
  62. System.ArgumentException: The field '__document_id' is not indexed, cannot query on fields that are not indexed