当存在多个嵌套元素匹配条件时,Elasticsearch仅获取文档

时间:2018-09-09 09:52:46

标签: elasticsearch kibana

我有一些带有嵌套附件对象的消息。我只需要提取具有(名称为 txt.txt 附件类型)和 AND (具有 Inline 名称 jpg.jpg )。

[{
   "id": 1,
   "hasAttachments": true,
   "attachmentCount": 2,
   "attachments": [
      {
         "type": "Attachment",
         "name": "a.txt",
         "mimeType": "text/plain"
      },
      {
         "type": "Inline",
         "name": "jpg.jpg",
         "mimeType": "image/jpeg"
      }
   ]  
},
{
   "id": 2,
   "hasAttachments": true,
   "attachmentCount": 2,
   "attachments": [
      {
         "type": "Attachment",
         "name": "txt.txt",
         "mimeType": "text/plain"
      },
      {
         "type": "Inline",
         "name": "jpg.jpg",
         "mimeType": "image/jpeg"
      }
   ]  
}]

这是我尝试过的:

{
  "query": {
    "nested": {
      "path": "attachments",
      "score_mode": "avg",
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "attachments.type": "Attachment"
              }
            },
            {
              "match": {
                "attachments.name": "txt.txt"
              }
            }
          ]
        }
      }
    }
  }
}

这为我提供了匹配的文档,但是如何包装这些结果并应用另一个过滤器。从那时起我迷路了。我们非常感谢您的帮助。

0 个答案:

没有答案