我有一个很好的MultiMap / Reduce索引,但我现在想查询其中一个字段......但该字段位于子对象中...
ReduceResult
- Name
- Description
- GenreObject
- Name
- Code
我尝试了各种选项,但我仍然收到以下错误:
Index(x => x.Genre.Code, FieldIndexing.Analyzed);
Store(x => x.Genre.Code, FieldStorage.Yes);
或 索引(x => x.Genre,FieldIndexing.Analyzed); 存储(x => x.Genre,FieldStorage.Yes);
我可以在管理控制台中看到它已将“Code”字段编入索引,但它似乎在寻找Genre_Code。
Url: "/indexes/AudioWithCounters?query=Genre_Code%253Ahouse&start=0&pageSize=25&aggregation=None&sort=-WeeksComments"
System.ArgumentException: The field 'Genre_Code' is not indexed, cannot query on fields that are not indexed
我尝试在管理控制台中手动将索引字段名称更改为“Genre_Code”,但似乎没有保存。
我知道我可能会恭维我的Genre对象,但如果我可以侥幸逃脱它,那就不是。
有什么想法吗?
更新 - 完整索引:
namespace HM.Web.Infrastructure.Indexes
{
public class AudioWithCounters : AbstractMultiMapIndexCreationTask<AudioWithCounters.AudioViewModel>
{
public class AudioViewModel
{
public string Id { get; set; }
public string ArtistName { get; set; }
public string Name { get; set; }
public string Identifier { get; set; }
public string Description { get; set; }
public IList<Tag> Tags { get; set; }
public Genre Genre { get; set; }
public DateTimeOffset? DateAdded { get; set; }
public UserImage Image { get; set; }
public int TotalComments { get; set; }
public int TotalDownloads { get; set; }
public int TotalPlays { get; set; }
public int TotalLikes { get; set; }
public int TotalFavourites { get; set; }
public int WeeksComments { get; set; }
public int WeeksDownloads { get; set; }
public int WeeksPlays { get; set; }
public int WeeksLikes { get; set; }
public int WeeksFavourites { get; set; }
}
public AudioWithCounters()
{
AddMap<Audio>(audios => from audio in audios
select new
{
Id = audio.Id,
ArtistName = audio.ArtistName,
Name = audio.Name,
Identifier = audio.Identifier,
Description = audio.Description,
Tags = audio.Tags,
Genre = audio.Genre,
DateAdded = audio.DateAdded,
Image = audio.Image,
TotalDownloads = 0,
TotalComments = audio.CommentsCount,
TotalPlays = 0,
TotalLikes = 0,
TotalFavourites = 0,
WeeksDownloads = 0,
WeeksPlays = 0,
WeeksComments = 0,
WeeksLikes = 0,
WeeksFavourites = 0
});
AddMap<AudioComments>(comments => from audioComment in comments
from comment in audioComment.Comments
where comment.CreatedAt >= DateTimeOffset.Now.AddDays(-7)
select new
{
Id = audioComment.Audio.Id,
ArtistName = (string)null,
Name = (string)null,
Identifier = (string)null,
Description = (string)null,
Tags = (object)null,
Genre = (object)null,
DateAdded = (object)null,
Image = (object)null,
TotalDownloads = 0,
TotalComments = 0,
TotalPlays = 0,
TotalLikes = 0,
TotalFavourites = 0,
WeeksDownloads = 0,
WeeksPlays = 0,
WeeksComments = 1,
WeeksLikes = 0,
WeeksFavourites = 0
});
AddMap<AudioCounter>(counters => from counter in counters
where counter.Type == Core.Enums.Audio.AudioCounterType.Download
select new
{
Id = counter.AudioId,
ArtistName = (string)null,
Name = (string)null,
Identifier = (string)null,
Description = (string)null,
Tags = (object)null,
Genre = (object)null,
DateAdded = (object)null,
Image = (object)null,
TotalDownloads = 1,
TotalComments = 0,
TotalPlays = 0,
TotalLikes = 0,
TotalFavourites = 0,
WeeksDownloads = 0,
WeeksPlays = 0,
WeeksComments = 0,
WeeksLikes = 0,
WeeksFavourites = 0
});
AddMap<AudioCounter>(counters => from counter in counters
where counter.Type == Core.Enums.Audio.AudioCounterType.Play
select new
{
Id = counter.AudioId,
ArtistName = (string)null,
Name = (string)null,
Identifier = (string)null,
Description = (string)null,
Tags = (object)null,
Genre = (object)null,
DateAdded = (object)null,
Image = (object)null,
TotalDownloads = 0,
TotalPlays = 1,
TotalComments = 0,
TotalLikes = 0,
TotalFavourites = 0,
WeeksDownloads = 0,
WeeksPlays = 0,
WeeksComments = 0,
WeeksLikes = 0,
WeeksFavourites = 0
});
AddMap<AudioCounter>(counters => from counter in counters
where counter.Type == Core.Enums.Audio.AudioCounterType.Download
where counter.DateTime >= DateTimeOffset.Now.AddDays(-7)
select new
{
Id = counter.AudioId,
ArtistName = (string)null,
Name = (string)null,
Identifier = (string)null,
Description = (string)null,
Tags = (object)null,
Genre = (object)null,
DateAdded = (object)null,
Image = (object)null,
TotalDownloads = 0,
TotalPlays = 0,
TotalComments = 0,
TotalLikes = 0,
TotalFavourites = 0,
WeeksDownloads = 1,
WeeksPlays = 0,
WeeksComments = 0,
WeeksLikes = 0,
WeeksFavourites = 0
});
AddMap<Like>(likes => from like in likes
select new
{
Id = like.AudioId,
ArtistName = (string)null,
Name = (string)null,
Identifier = (string)null,
Description = (string)null,
Tags = (object)null,
Genre = (object)null,
DateAdded = (object)null,
Image = (object)null,
TotalDownloads = 0,
TotalPlays = 0,
TotalComments = 0,
TotalLikes = 1,
TotalFavourites = 0,
WeeksDownloads = 0,
WeeksPlays = 0,
WeeksComments = 0,
WeeksLikes = 0,
WeeksFavourites = 0
});
AddMap<Favourite>(favs => from fav in favs
select new
{
Id = fav.AudioId,
ArtistName = (string)null,
Name = (string)null,
Identifier = (string)null,
Description = (string)null,
Tags = (object)null,
Genre = (object)null,
DateAdded = (object)null,
Image = (object)null,
TotalDownloads = 0,
TotalPlays = 0,
TotalComments = 0,
TotalLikes = 0,
TotalFavourites = 1,
WeeksDownloads = 0,
WeeksPlays = 0,
WeeksComments = 0,
WeeksLikes = 0,
WeeksFavourites = 0
});
AddMap<AudioCounter>(counters => from counter in counters
where counter.Type == Core.Enums.Audio.AudioCounterType.Play
where counter.DateTime >= DateTimeOffset.Now.AddDays(-7)
select new
{
Id = counter.AudioId,
ArtistName = (string)null,
Name = (string)null,
Identifier = (string)null,
Description = (string)null,
Tags = (object)null,
Genre = (object)null,
DateAdded = (object)null,
Image = (object)null,
TotalDownloads = 0,
TotalPlays = 0,
TotalComments = 0,
TotalLikes = 0,
TotalFavourites = 0,
WeeksDownloads = 1,
WeeksPlays = 0,
WeeksComments = 0,
WeeksLikes = 0,
WeeksFavourites = 0
});
AddMap<Like>(likes => from like in likes
where like.DateCreated >= DateTimeOffset.Now.AddDays(-7)
select new
{
Id = like.AudioId,
ArtistName = (string)null,
Name = (string)null,
Identifier = (string)null,
Description = (string)null,
Tags = (object)null,
Genre = (object)null,
DateAdded = (object)null,
Image = (object)null,
TotalDownloads = 0,
TotalPlays = 0,
TotalComments = 0,
TotalLikes = 0,
TotalFavourites = 0,
WeeksDownloads = 0,
WeeksPlays = 0,
WeeksComments = 0,
WeeksLikes = 1,
WeeksFavourites = 0
});
AddMap<Favourite>(favs => from fav in favs
where fav.DateCreated >= DateTimeOffset.Now.AddDays(-7)
select new
{
Id = fav.AudioId,
ArtistName = (string)null,
Name = (string)null,
Identifier = (string)null,
Description = (string)null,
Tags = (object)null,
Genre = (object)null,
DateAdded = (object)null,
Image = (object)null,
TotalDownloads = 0,
TotalPlays = 0,
TotalComments = 0,
TotalLikes = 0,
TotalFavourites = 0,
WeeksDownloads = 0,
WeeksPlays = 0,
WeeksComments = 0,
WeeksLikes = 0,
WeeksFavourites = 1
});
Reduce = results => from result in results
group result by result.Id
into g
select new
{
Id = g.Key,
ArtistName = g.Select(x => x.ArtistName).Where(x => x != null).FirstOrDefault(),
Name = g.Select(x => x.Name).Where(x => x != null).FirstOrDefault(),
Identifier = g.Select(x => x.Identifier).Where(x => x != null).FirstOrDefault(),
Description = g.Select(x => x.Description).Where(x => x != null).FirstOrDefault(),
Tags = g.Select(x => x.Tags).Where(x => x != null).FirstOrDefault(),
Genre = g.Select(x => x.Genre).Where(x => x != null).FirstOrDefault(),
DateAdded = g.Select(x => x.DateAdded).Where(x => x != null).FirstOrDefault(),
Image = g.Select(x => x.Image).Where(x => x != null).FirstOrDefault(),
TotalDownloads = g.Sum(x => x.TotalDownloads),
TotalPlays = g.Sum(x => x.TotalPlays),
TotalComments = g.Sum(x => x.TotalComments),
TotalLikes = g.Sum(x => x.TotalLikes),
TotalFavourites = g.Sum(x => x.TotalFavourites),
WeeksComments = g.Sum(x => x.WeeksComments),
WeeksDownloads = g.Sum(x => x.WeeksDownloads),
WeeksPlays = g.Sum(x => x.WeeksPlays),
WeeksLikes = g.Sum(x => x.WeeksLikes),
WeeksFavourites = g.Sum(x => x.WeeksFavourites)
};
Index(x => x.Genre.Code, FieldIndexing.Analyzed);
Store(x => x.Genre.Code, FieldStorage.Yes);
}
}
}
答案 0 :(得分:1)
您看到的问题是因为Genre.Code字段不是索引。 Map / Reduce索引的输出是Reduce语句,它不包含Genre.Code字段。
Reduce = results => from result in results
group result by result.Id
into g
select new
{
Id = g.Key,
ArtistName = g.Select(x => x.ArtistName).Where(x => x != null).FirstOrDefault(),
Name = g.Select(x => x.Name).Where(x => x != null).FirstOrDefault(),
Identifier = g.Select(x => x.Identifier).Where(x => x != null).FirstOrDefault(),
Description = g.Select(x => x.Description).Where(x => x != null).FirstOrDefault(),
Tags = g.Select(x => x.Tags).Where(x => x != null).FirstOrDefault(),
Genre = g.Select(x => x.Genre).Where(x => x != null).FirstOrDefault(),
DateAdded = g.Select(x => x.DateAdded).Where(x => x != null).FirstOrDefault(),
Image = g.Select(x => x.Image).Where(x => x != null).FirstOrDefault(),
TotalDownloads = g.Sum(x => x.TotalDownloads),
TotalPlays = g.Sum(x => x.TotalPlays),
TotalComments = g.Sum(x => x.TotalComments),
TotalLikes = g.Sum(x => x.TotalLikes),
TotalFavourites = g.Sum(x => x.TotalFavourites),
WeeksComments = g.Sum(x => x.WeeksComments),
WeeksDownloads = g.Sum(x => x.WeeksDownloads),
WeeksPlays = g.Sum(x => x.WeeksPlays),
WeeksLikes = g.Sum(x => x.WeeksLikes),
WeeksFavourites = g.Sum(x => x.WeeksFavourites)
};
仅将字段设置为Stored
并不能解决问题。
但是更大的问题是为什么要编写这样的索引,请参阅上面的评论。