【问题标题】:Bool Filter not showing just the filtered data in Elastic Search布尔过滤器不只显示弹性搜索中的过滤数据
【发布时间】:2020-06-01 20:06:37
【问题描述】:

我有一个索引“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"
                }}
            ]
        }
    }
}

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

{
        "_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"
            }
          ]
        }
      }

【问题讨论】:

    标签: elasticsearch lucene elasticsearch-query elasticsearch-nested


    【解决方案1】:

    已经回答hereherehere

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      相关资源
      最近更新 更多