elasticsearch 基于属性的索引提示更改我的结果
我有一个查询,自从我第一次让它工作以来一直没有改变:elasticsearch 基于属性的索引提示更改我的结果,elasticsearch,elasticsearch-net,elasticsearch,elasticsearch Net,我有一个查询,自从我第一次让它工作以来一直没有改变: ISearchResponse<Series> response = await IndexManager.GetClient() .SearchAsync<Series>(r => r .Filter(f => f.Term<Role>(t => t.ReleasableTo.First(), Role.Visitor)) .SortDescend
ISearchResponse<Series> response = await IndexManager.GetClient()
.SearchAsync<Series>(r => r
.Filter(f => f.Term<Role>(t => t.ReleasableTo.First(), Role.Visitor))
.SortDescending(ser => ser.EndDate)
.Size(1));
虽然这一切都很好,但对我们存储的每种类型都这样做并不能很好地扩展。因此,我有意识地决定使用属性并以这种方式进行映射:
// In IndexManager
client.Map<T>(m => m.MapFromAttributes());
// In the type definition
class Series
{
// ....
[DataMember]
[ElasticProperty(Index = FieldIndexOption.NotAnalyzed, Store = true)]
public HashSet<Role> ReleasableTo { get; set; }
// ....
}
//在IndexManager中
client.Map(m=>m.MapFromAttributes());
//在类型定义中
类系列
{
// ....
[数据成员]
[ElasticProperty(Index=FieldIndexOption.notanalyze,Store=true)]
公共HashSet ReleasableTo{get;set;}
// ....
}
一旦我这样做,我就不再有结果了。当我在Kibana中查看我的索引时,我看到我的“releasableTo”字段没有被分析,而是被索引了。然而,我编写的查询不再有效。如果我删除filter子句,我会得到结果,但我真的需要它来工作
我错过了什么?如何使查询再次工作?提供索引提示的ElasticSearch属性似乎不知道如何处理
enum
s
问题是角色
类型是枚举。client.Map(m=>m.MapFromAttributes())
调用跳过了该属性。在运行时,它会将属性动态映射到字符串
// In the type definition
class Series
{
// ....
[DataMember]
[ElasticProperty(Index = FieldIndexOption.NotAnalyzed, Store = true)]
public HashSet<Role> ReleasableTo { get; set; }
// ....
}
使我的查询再次起作用。这个故事的寓意是,除非它是原始类型,否则在设置字段类型时要明确。我甚至不知道如何开始修复它。。。有人有输入吗?不知道您正在使用的框架,您是否有方法在生成的查询发送到ES时检查它们,并有方法比较每种情况下的映射?我使用的是C#NEST API。以前的查询不再有效。不确定ES如何处理动态映射与基于属性的显式映射。我已经使用kibana和ES API来查看映射,但是没有什么明显的效果http://your_host:9200/your_index/_mapping?pretty从索引中获取完整映射。我建议比较每种情况下的映射,看看是否存在任何差异。Elasticsearch也有“动态映射”,如果你想走超级懒散的路线,它会在第一次看到某个字段时猜测该字段的映射。这里有些东西没有加起来。我有很多属性,其中弹性属性索引选项得到了尊重,但“releasableTo”索引却没有。因此,虽然这解释了为什么terms查询失败,但它并没有解释为什么这个特定属性不受尊重,而所有其他属性都不受尊重。我有正确设置的混合大小写属性和绑定到正确设置的哈希集的属性。“releasableTo”是ES中的保留字吗?仅供参考。与@greg marzouka(核心嵌套开发人员)交谈。他将重新讨论这个问题。@pickypg,谢谢。我也在那边称重。希望它能引起一些关注。如果没有,我将用我的反建议重新打开它:)对上述问题的修复使其成为一个问题。
// In the type definition
class Series
{
// ....
[DataMember]
[ElasticProperty(Index = FieldIndexOption.NotAnalyzed, Store = true)]
public HashSet<Role> ReleasableTo { get; set; }
// ....
}
// In the type definition
class Series
{
// ....
[DataMember]
[ElasticProperty(Index = FieldIndexOption.NotAnalyzed, Type = FieldType.String, Store = true)]
public HashSet<Role> ReleasableTo { get; set; }
// ....
}