Class Mail
{
public string MailID {get;set;}
[nested]
public List<Attachment> attachments {get;set;}
}
Class Attachment
{
public int AttachmentID {get;set;}
public string Data {get; set;}
[nested]
public Nest.attachment {get;set;}
}
上面是我的带有Ingest-Pipeline数据的索引结构,已正确索引,但是当尝试搜索附件内容时,它会返回带有所有附件以及实际搜索附件的孔附件对象。
在结果中,我只需要带有搜索结果的附件
以下是我的查询
var response1 = elasticClient.Search<Mail>(s => s
.Index(indexName)
.Query(q =>
q.Match(mq => mq.Field("attachments.attachment.content").Query("b"))
));
最佳答案
由于附件是一个嵌套字段,因此您需要使用nested query
.Nested(c => c
.Path(p => p.attachments)
.InnerHits = new InnerHits {},
.Query(q =>
q.Match(mq => mq.Field("attachments.attachment.content").Query("b"))
))
作为回应,您需要从内部匹配中读取对象
关于elasticsearch - ElasticSearch.net附件搜索数组正在返回带有搜索结果的所有附件,如何仅检索匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60666083/