【问题标题】:ElasticSearch.net Array of Attachment Search is returning all attachments with search results how to retrieve only hitsElasticSearch.net 附件搜索数组正在返回带有搜索结果的所有附件如何仅检索命中
【发布时间】:2020-06-25 05:03:51
【问题描述】:
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"))
                                           ));

【问题讨论】:

  • 在映射中嵌套或对象的附件类型是什么?
  • 它是一个嵌套对象

标签: elasticsearch indexing attachment elasticsearch.net


【解决方案1】:

由于附件是嵌套字段,您需要使用nested query

.Nested(c => c
    .Path(p => p.attachments)
    .InnerHits = new InnerHits {},
    .Query(q =>
           q.Match(mq => mq.Field("attachments.attachment.content").Query("b"))
))

作为响应,您需要从内部点击中读取对象

【讨论】:

  • 由于附件和附件都是嵌套类型,您是否尝试嵌套到第二级 ex q.Nested(n => n.Path("attachments") .Query(q2=> q2.Nested ( n2 => n2.Path("attachments.attachment") .Query(q3 =>
猜你喜欢
  • 2020-07-24
  • 1970-01-01
  • 1970-01-01
  • 2013-09-27
  • 2018-11-07
  • 1970-01-01
  • 2019-12-05
  • 1970-01-01
  • 2015-05-16
相关资源
最近更新 更多