Php client - Aggregation of documents with date interval

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 !

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