# Aggregation by names of the days

**URL:** <https://discuss.elastic.co/t/aggregation-by-names-of-the-days/184232>\
**Category:** Elasticsearch\
**Created:** [June 4, 2019, 5:06pm UTC](https://discuss.elastic.co/t/aggregation-by-names-of-the-days/184232 "2019-06-04T17:06:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpaz93](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpaz93/32/39371_2.png) [@jpaz93](https://discuss.elastic.co/u/jpaz93)\
**Post date:** [June 4, 2019, 5:06pm UTC](https://discuss.elastic.co/t/aggregation-by-names-of-the-days/184232/1 "2019-06-04T17:06:24Z")

</div>

Hi,  
I need help with the following:

I need to make an aggregation to group by the names of the days

I have tried the following:

```
GET evento/_search
{
  "size": 0, 
  "query": {
      "range": {
         "datetime1": {
            "gte": "2019-01-01 00:00:00",
            "lte": "2019-05-31 23:59:59"
          }
       }
  },
  "aggs": {
    "perWeekDay": {
      "terms": {
        "script": {
          "source": """
            Date date = new Date(doc.datetime1.value.dayOfMonth); 
            java.text.SimpleDateFormat format = new java.text.SimpleDateFormat('EEEE'); 
            format.format(date)
            """
        }
      }
    }
  }
}

```

> This throws the grouping only by Wednesday

```
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 257,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "perWeekDay": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "Wednesday",
          "doc_count": 257
        }
      ]
    }
  }
}

```

I have also used date\_histogram and when the range is several weeks or months the days are repeated:

```
GET evento/_search
{
  "size": 0,
  "query": {
    "range": {
      "evg_fecha_creacion": {
        "gte": "2019-01-01 00:00:00",
        "lte": "2019-05-31 23:59:59"
      }
    }
  },
  "aggs": {
    "qwre": {
      "date_histogram": {
        "field": "datetime1",
        "interval": "day",
        "format": "EEEE",
        "min_doc_count": 1
      }
    }
  }
}

```

---

<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:** [July 2, 2019, 5:06pm UTC](https://discuss.elastic.co/t/aggregation-by-names-of-the-days/184232/2 "2019-07-02T17:06:25Z")

</div>

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