Bool Filter 不只显示 Elastic Search 中过滤后的数据

Bool Filter not showing just the filtered data in Elastic Search

我有一个索引 "tag_nested",其中包含以下类型的数据:

{
    "jobid": 1,
    "table_name": "table_A",
    "Tags": [
      {
        "TagType": "WorkType",
        "Tag": "ETL"
      },
      {
        "TagType": "Subject Area",
        "Tag": "Telecom"
      }
    ]
}

当我触发查询以通过触发以下查询过滤 "Tag" 和 "TagType" 上的数据时:

POST /tag_nested/_search
{
    "query": {
        "bool": {
            "must": {"match_all": {}},
            "filter": [
                {"term": {
                    "Tags.Tag.keyword": "ETL"
                }},
                 {"term": {
                    "Tags.TagType.keyword": "WorkType"
                }}
            ]
        }
    }
}

它给了我以下输出。我面临的问题是,虽然上面的查询过滤了没有过滤数据的文档,但它显示了该文档的所有 "Tags" 而不仅仅是过滤器一个

{
        "_index" : "tag_nested",
        "_type" : "_doc",
        "_id" : "9",
        "_score" : 1.0,
        "_source" : {
          "jobid" : 1,
          "table_name" : "table_A",
          "Tags" : [
            {
              "TagType" : "WorkType",
              "Tag" : "ETL"
            },
            {
              "TagType" : "Subject Area",
              "Tag" : "Telecom"
            }
          ]
        }
      }

我希望我的输出不是上面的结果:

{
        "_index" : "tag_nested",
        "_type" : "_doc",
        "_id" : "9",
        "_score" : 1.0,
        "_source" : {
          "jobid" : 1,
          "table_name" : "table_A",
          "Tags" : [
            {
              "TagType" : "WorkType",
              "Tag" : "ETL"
            }
          ]
        }
      }

已回答here, and

TL;DR 您需要将 Tags 字段设为 nested 类型,重新同步您的索引并使用 inner_hits 仅获取适用的标签组。