# Need to access DATA\_HISTOGRAM buckets response keys in child aggregation

**URL:** <https://discuss.elastic.co/t/need-to-access-data-histogram-buckets-response-keys-in-child-aggregation/231609>\
**Category:** Elasticsearch\
**Created:** [May 7, 2020, 6:45pm UTC](https://discuss.elastic.co/t/need-to-access-data-histogram-buckets-response-keys-in-child-aggregation/231609 "2020-05-07T18:45:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![viralshah1494](https://avatars.discourse-cdn.com/v4/letter/v/f0a364/32.png) [@viralshah1494](https://discuss.elastic.co/u/viralshah1494)\
**Post date:** [May 7, 2020, 6:45pm UTC](https://discuss.elastic.co/t/need-to-access-data-histogram-buckets-response-keys-in-child-aggregation/231609/1 "2020-05-07T18:45:52Z")

</div>

I want to apply some filters on the bucket response generated by the `date_histogram` , that filter is dependent on the key of the `date_histogram` output buckets.

Suppose I have following data in

```auto
{
   "entryTime":"",
   "soldTime:""
}

```

the elastic query is something like this

```auto
    {
      "aggs": {
        "date": {
          "date_histogram": {
            "field": "entryTime",
            "interval": "month",
            "keyed": true
          },
          "aggs": {
            "filter_try": {
              "filter": {
                "bool": {
                  "must": [
                    {
                      "range": {
                        "entryTime": {
                          "lte": 1588840533000
                        }
                      }
                    },
                    {
                      "bool": {
                        "should": [
                          {
                            "bool": {
                              "must": [
                                {
                                  "exists": {
                                    "field": "soldTime"
                                  }
                                },
                                {
                                  "range": {
                                    "soldTime": {
                                      "gt": 1588840533000
                                    }
                                  }
                                }
                              ]
                            }
                          },
                          {
                            "bool": {
                              "must_not": [
                                {
                                  "exists": {
                                    "field": "soldTime"
                                  }
                                }
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }

```

So here in that bool query, I want to use the date generated for the specific bucket by `date_histogram` aggregation in both the range clauses instead of the hardcoded epoch time.

Even if we can access using script then also it's fine.

for further clarification, this is the boolean query and in the query want to replace this `"DATE"` with the `date_histogram` bucket key.

```auto
# (entryTime < DATE) 
# AND 
# (
# (soldTime != null AND soldTime > DATE) 
# OR 
# (soldTime == NULL)
# )

```

Thank you

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 4, 2020, 6:45pm UTC](https://discuss.elastic.co/t/need-to-access-data-histogram-buckets-response-keys-in-child-aggregation/231609/2 "2020-06-04T18:45:54Z")

</div>

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