elasticsearch - ElasticSearch.net附件搜索数组正在返回带有搜索结果的所有附件,如何仅检索匹配

标签 elasticsearch indexing attachment elasticsearch.net

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/

相关文章:

amazon-web-services - 如何进行地理距离查询仅返回尚未返回的结果 “Liked”,Elastic Search,Dynamo DB

elasticsearch - Elasticsearch 使用上下文加载CSV数据

indexing - 文本语料库遵循zipf定律的知识的优点是什么?

python - 如何在Python中获取数组中所有NaN元素的索引?

python - 在 Python 中使用 Selenium 上传文件

c# - 带 SDK 的 Dynamics CRM 2011 附加文件

elasticsearch - 在Elasticsearch索引中为每个字段建立索引都有不利之处吗?

security - 保护 Elasticsearch 集群

mongodb - Mongodb 中的文本搜索不起作用

ios - 将附件发送到 QuickBlox IOS sdk