# Php client - Aggregation of documents with date interval

**URL:** <https://discuss.elastic.co/t/php-client-aggregation-of-documents-with-date-interval/156609>\
**Category:** Elasticsearch\
**Created:** [November 14, 2018, 9:14am UTC](https://discuss.elastic.co/t/php-client-aggregation-of-documents-with-date-interval/156609 "2018-11-14T09:14:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keb](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@Keb](https://discuss.elastic.co/u/Keb)\
**Post date:** [November 14, 2018, 9:14am UTC](https://discuss.elastic.co/t/php-client-aggregation-of-documents-with-date-interval/156609/1 "2018-11-14T09:14:40Z")

</div>

Hello,

I'm trying to use Elasticsearch and stumbled across a problem I can't resolve. I posted my question on stackoverflow, but I might aswell ask for your help here.

I'm trying to build a faceted search using Elasticsearch-php 6.0, but I'm having a hard time to figure out how to use a date range aggregation. Here's what I'm trying to do :

Mapping sample :

```
"mappings": {
  "_doc": {
    "properties": {
      ...
      "timeframe": {
        "properties": {
          "gte": {
            "type": "date",
            "format": "yyyy"
          },
          "lte": {
            "type": "date",
            "format": "yyyy"
          }
        }
      }
      ...

```

In my document, I have this property:

```
"timeframe":[{"gte":"1701","lte":"1800"}]

```

I want to be able display a facet with a date range slider, where the user can input a range (min value - max value). Ideally, those min-max values should be returned by the Elasticsearch aggregation automatically given the current query.

Here's the aggregation I'm trying to write in "pseudo code", to give you an idea:

```
"aggs": {
  "date_range": {
      "field": "timeframe",
      "format": "yyyy",
      "ranges": [{
          "from": min(timeframe.gte),
          "to": max(timeframe.lte)
      }]
  }
}

```

Of course this will be translated to php, but for learning purpose, I sometime use the kibana console.

I think I need to use Date Range aggregation, min/max aggregation, and pipeline aggregations, but the more I read about them, the more I'm confused. I can't find how to glue this whole world together.

Keep in mind I can change the mapping and / or the document structure if this is not the correct way to achieve this.

Thanks !

---

<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:** [December 12, 2018, 9:15am UTC](https://discuss.elastic.co/t/php-client-aggregation-of-documents-with-date-interval/156609/2 "2018-12-12T09:15:01Z")

</div>

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