Aggregation by names of the days

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
      }
    }
  }
}

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