我现在学习了针对elasticsearch的Nest 6.x客户端我想在子文档中使用术语搜索。我有这个课程:
public class BaseTest
{
public string Id { get; set; }
public SubBase SubDocument { get; set; }
public Guid TypeId { get; set; }
public string BaseTitel { get; set; }
}
public class SubBase
{
public int Id { get; set; }
public Guid IdGuid { get; set; }
public string Titel { get; set; }
}
并使用此映射创建索引:
.Mappings(mp => mp
.Map<BaseTest>(m => m
.Properties(pr => pr
.Keyword(kw => kw
.Name(nm => nm.BaseTitel)))
.Properties(pr => pr
.Keyword(kw => kw
.Name(nm => nm.TypeId)))
.Properties(pr => pr
.Keyword(kw => kw
.Name(nm => nm.SubDocument.Titel)))
.Properties(pr => pr
.Keyword(kw => kw
.Name(nm => nm.SubDocument.IdGuid)
))))
wenn我尝试在BaseTest中搜索GUID(或GUID格式的字符串,我将SubBase.Titel保存为Guid for tests)值,但不在SubBase中。 要搜索我使用此查询:
.Query(q => q
.ConstantScore(cs => cs
.Filter(f => f
.Term(t => t
.SubDocument.Titel, "5d511b8a-37c7-40c1-a5c3-4de13e16e379"))))
更新
新映射:
.Mappings(mp => mp
.Map<BaseTest>(m => m
.Properties(pr => pr
.Keyword(kw => kw
.Name(nm => nm.BaseTitel)
.Name(nm => nm.TypeId)
)
.Object<SubBase>(o => o
.Name(n => n.SubDocument)
.Properties(p => p
.Keyword(k => k
.Name(n => n.Titel)
.Name(n => n.IdGuid)))))))
现在我可以找到Guid属性,但不能找到类型字符串的值,例如&#34; 5d511b8a-37c7-40c1-a5c3-4de13e16e379&#34;
答案 0 :(得分:0)
感谢Russ Cam
.Mappings(mp => mp
.Map<BaseTest>(m => m
.Properties(pr => pr
.Keyword(kw => kw
.Name(nm => nm.BaseTitel))
.Keyword(kw => kw
.Name(nm => nm.TypeId))
.Object<SubBase>(o => o
.Name(n => n.SubDocument)
.Properties(p => p
.Keyword(k => k
.Name(n => n.Titel))
.Keyword(k => k
.Name(n => n.IdGuid)))))))