# Group Results by Timestamp Ignoring Hours

**URL:** <https://discuss.elastic.co/t/group-results-by-timestamp-ignoring-hours/269643>\
**Category:** Elasticsearch\
**Created:** [April 8, 2021, 8:17pm UTC](https://discuss.elastic.co/t/group-results-by-timestamp-ignoring-hours/269643 "2021-04-08T20:17:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [April 8, 2021, 8:17pm UTC](https://discuss.elastic.co/t/group-results-by-timestamp-ignoring-hours/269643/1 "2021-04-08T20:17:31Z")

</div>

My document mapping has a date property in the strict\_date\_time\_no\_millis format.  
However, when doing an aggregation based on this property, it also uses the hours. Is it possible to perform the aggregation using only the date and ignoring the hours?

Another issue is that the field I use for aggregation is a string to store the evaluation of a sale. Ex .: G-Good, B-Bad, N-Neutral.

Is it possible to convert these letters to make an average? Ex .: G = 2, N = 1, B-0

```
{
    "size": 0,
    "_source": false,
    "stored_fields": "_none_",
    "aggregations": {
        "groupby": {
            "composite": {
                "size": 1000,
                "sources": [
                    {
                        "1728": {
                            "terms": {
                                "field": "sale_date",
                                "missing_bucket": true,
                                "order": "asc"
                            }
                        }
                    }
                ]
            },
            "aggregations": {
                "1790": {
                    "avg": {
                        "field": "Converted_Rating_Field"
                    }
                }
            }
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [April 9, 2021, 6:20pm UTC](https://discuss.elastic.co/t/group-results-by-timestamp-ignoring-hours/269643/2 "2021-04-09T18:20:29Z")

</div>

Problem Solved:

```
{
    "size": 0,
    "_source": false,
    "stored_fields": "_none_",
    "aggs" : {
        "sales_over_time" : {
            "date_histogram" : {
                "field" : "sale_date",
                "interval" : "day",
                "format": "dd/MM/yyyy",
                "time_zone": "-0300"
            },
             "aggs": {
                "review": {
                    "avg": {
                        "script": {
                            "lang": "painless",
                            "source": "if (doc.review.value=='P'){return 1;} else if (doc.review.value=='R'){return 2;} else if (doc.review.value=='M'){return 3;} else if (doc.review.value=='B'){return 4;}else if (doc.review.value=='O'){return 5;}else{return 0;}"
                        }
                    }
                }
            }
        }
    }
}
```

---

<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:** [May 7, 2021, 6:21pm UTC](https://discuss.elastic.co/t/group-results-by-timestamp-ignoring-hours/269643/3 "2021-05-07T18:21:20Z")

</div>

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