C# 使用.NET Core中的嵌套对ElasticSearch中的嵌套集合执行查询
我正在尝试对以下对象的索引执行搜索:C# 使用.NET Core中的嵌套对ElasticSearch中的嵌套集合执行查询,c#,elasticsearch,asp.net-core,.net-core,nest,C#,elasticsearch,Asp.net Core,.net Core,Nest,我正在尝试对以下对象的索引执行搜索: public class IndexedElement { public Guid Id { get; set; } public long RowId { get; set; } public IndexedElementType Type { get; set; } public string Summary { get; set; } public string Description { get; set;
public class IndexedElement
{
public Guid Id { get; set; }
public long RowId { get; set; }
public IndexedElementType Type { get; set; }
public string Summary { get; set; }
public string Description { get; set; }
public IList<string> Tags { get; set; }
}
公共类索引删除
{
公共Guid Id{get;set;}
公共长RowId{get;set;}
公共IndexedElementType类型{get;set;}
公共字符串摘要{get;set;}
公共字符串说明{get;set;}
公共IList标记{get;set;}
}
其目的是通过Summary属性或通过匹配标记集合中的任何字符串进行搜索
我目前拥有的是:
public IEnumerable<IndexedElement> Search(string description)
{
var query = GetClient().Search<IndexedElement>(s => s.From(0).Size(5)
.Query(
q => q.Term(p => p.Summary, description)
||
q.Nested(n => n.Path(p => p.Tags).Query(q2 => q2.Terms(t => t.Field(f => f.Tags).Terms(description))))
));
return query.Documents.ToList();
}
公共IEnumerable搜索(字符串描述)
{
var query=GetClient().Search(s=>s.From(0).Size(5)
.查询(
q=>q.术语(p=>p.摘要、描述)
||
q、 嵌套(n=>n.Path(p=>p.Tags).Query(q2=>q2.Terms(t=>t.Field(f=>f.Tags).Terms(description)))
));
返回query.Documents.ToList();
}
但是嵌套部分不起作用,我不知道我是否以正确的方式使用它,或者我必须找到另一种解决方案
有什么想法吗
提前感谢大家您不需要执行
嵌套
查询来查询标记
字段,因为每个标记都只是一个原始JSON值,即字符串
。只需术语
查询即可
如果需要嵌套
查询,则标记
是具有多个属性的POCO,并映射为嵌套
数据类型