elasticsearch 排除空子存储桶ElasticSearch,elasticsearch,filter,elasticsearch,Filter" /> elasticsearch 排除空子存储桶ElasticSearch,elasticsearch,filter,elasticsearch,Filter" />

elasticsearch 排除空子存储桶ElasticSearch

elasticsearch 排除空子存储桶ElasticSearch,elasticsearch,filter,elasticsearch,Filter,我编写了一个具有两个级别的聚合查询: { "size": 0, "aggregations": { "colors": { "terms": { "field": "color" }, "aggregations": { "timestamps": { "date_histogram": { "field": "timestamp", "inte

我编写了一个具有两个级别的聚合查询:

{
  "size": 0,
  "aggregations": {
    "colors": {
      "terms": {
        "field": "color"
      },
      "aggregations": {
        "timestamps": {
          "date_histogram": {
            "field": "timestamp",
            "interval": "1m",
            "order": {
              "_key": "desc"
            }
          },
          "aggregations": {
            "timestamps_bucket_filter": {
              "bucket_selector": {
                "buckets_path": {
                  "counterts": "_count"
                },
                "script": {
                  "lang": "expression",
                  "script": "counterts == 0"
                }
              }
            }
          }
        }
      }
    }
  }
}
可以看出,我只过滤了零文档的所有子bucket时间戳。 问题是,在上述过滤之后,在高级bucket颜色中存在空bucket

例如:

.
.
.
"aggregations": {
  "colors": {
    "doc_count_error_upper_bound": 12144,
    "sum_other_doc_count": 14785757,
    "buckets": [
      .
      .
      .,
      {
        "key": "Yellow",    // <<-- this is an empty bucket I would like to exclude
        "doc_count": 57223,
        "timestamps": {
          "buckets": [
                            // <<-- empty
          ]
        }
      },
      .
      .
      .
如何从任何时间戳子存储桶中排除仍为空的所有颜色存储桶

提前谢谢

根据,您可以指定要包括的存储桶的最小单据数:

     "date_histogram": {
        "field": "timestamp",
        "interval": "1m",
        "min_doc_count" : 1,
        "order": {
          "_key": "desc"
        }
      },

回到这里,我刚刚发现最近有一个问题和PR,它将_bucket _countpath添加到bucket _path选项中,以便聚合可以根据另一个聚合拥有的bucket数潜在地过滤父bucket。换句话说,如果父桶选择器的桶计数为0,则应移除该桶


这就是github的问题:

谢谢您的回答。它不起作用,您当前试图从子聚合中排除,使用零过滤器,将永远不会有子存储桶。我需要的是从主聚合颜色中排除…是的,我尝试将min_doc_count=0放在颜色聚合下-不起作用。也许我做得不对。@Eli您试图对颜色分组的术语进行限制吗?是的。脚本排除包含更多零文档的时间戳子存储桶后,可以有空的颜色存储桶。那些空的颜色桶是我想要排除的桶。好吧,它不应该失败。这里还检查了术语聚合文档。你可以发布你当前的请求正文吗?我认为这是不可能的。没有帖子过滤或其他可以帮助你的东西?我不这么认为。基本上,您需要一个与您已经使用的类似的管道聚合,但在聚合树中只有一个级别。我试图让它像这样工作,但无法确定桶列表是否为空。聚合中使用的脚本可以访问_键、_计数和_项。这些都没有定义桶的emtpy列表。。。看起来很有趣。我猜它是5.x版的?是的,它将是5.x版的功能。