How can I filtering of child aggs on parent agg's key(date_histogram.key_as_string)

I want to Change filter.range.exitTime.lte:"2021-08"
to date_histogram.key_as_string
How do i make it

GET /workerentryexitrecord/_search
{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "project.id": "111111111111"
          }
        },
        {
          "match": {
            "isDelete": false
          }
        }
      ]
    }
  },
  "aggs": {
    "month_count": {
      "date_histogram": {
        "field": "entryTime",
        "interval": "month",
        "format": "8uuuu-MM",
        "min_doc_count": 0
      },
      "aggs": {
        "subBuckets": {
          "filter": {
            "range": {
              "exitTime": {
                "lte": "2021-08||/M"  #Replace with 【date_histogram.key_as_string】
              }
            }
          },
          "aggs": {
            "month_exit": {
              "value_count": {
                "field": "exitTime"
              }
            }
          }
        }
      }
    }
  }
}

result:

{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 22,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "aggregations" : {
    "month_count" : {
      "meta" : { },
      "buckets" : [
        {
          "key_as_string" : "2021-07",
          "key" : 1625097600000,
          "doc_count" : 1,
          "subBuckets" : {
            "doc_count" : 1,
            "month_exit" : {
              "value" : 1
            }
          }
        },
        {
          "key_as_string" : "2021-08",
          "key" : 1627776000000,
          "doc_count" : 21,
          "subBuckets" : {
            "doc_count" : 9,
            "month_exit" : {
              "value" : 9
            }
          }
        }
      ]
    }
  }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.