# Incorrect month in Elasticsearch date\_histogram

**URL:** <https://discuss.elastic.co/t/incorrect-month-in-elasticsearch-date-histogram/154561>\
**Category:** Elasticsearch\
**Created:** [October 30, 2018, 5:32am UTC](https://discuss.elastic.co/t/incorrect-month-in-elasticsearch-date-histogram/154561 "2018-10-30T05:32:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alinaqi306](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@alinaqi306](https://discuss.elastic.co/u/alinaqi306)\
**Post date:** [October 30, 2018, 5:32am UTC](https://discuss.elastic.co/t/incorrect-month-in-elasticsearch-date-histogram/154561/1 "2018-10-30T05:32:28Z")

</div>

My Document looks like below:

```
{
    "_index": "rep_cdr",
    "_type": "doc",
    "_id": "TaArd2YBDRXNehCp7GmW",
    "_score": 1,
    "_source": {
      "level": "info",
      "@version": "1",
      "thirdPartyTime": 139,
      "date": "15-10-2018",
      "time": "15:00:59",
      "reqId": "25718d6e-b8ef-438d-8218-1a8726c6c816",
      "TAT": 1574,
      "message": "",
      "thirdPartyErrorDescription": "",
      "@timestamp": "2018-10-15T10:00:59.146Z",
    }
 }

```

And I am running following query:

```
GET rep_cdr/doc/_search
{
  "size": 0,
  "aggs": {
    "datewise": {
      "date_histogram": {
       "field": "date",
       "interval": "day"
      }
    }
  }
}

```

I am getting below result:

```
{

  "aggregations": {
    "datewise": {
      "buckets": [
        {
          "key_as_string": "15-01-2018",
          "key": 1515974400000,
          "doc_count": 8
        }
      ]
    }
  }
}

```

The "key\_as\_string" gives me wrong month. In document the date field has value "15-10-2018" but "key\_as\_string" gives me "15-01-2018". I am using Elasticsearch version 6.4. What could be wrong?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 30, 2018, 5:44am UTC](https://discuss.elastic.co/t/incorrect-month-in-elasticsearch-date-histogram/154561/2 "2018-10-30T05:44:24Z")

</div>

Looks weird. What is the mapping?

---

<div class="post-metadata">

**Author:** ![alinaqi306](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@alinaqi306](https://discuss.elastic.co/u/alinaqi306)\
**Post date:** [October 30, 2018, 6:05am UTC](https://discuss.elastic.co/t/incorrect-month-in-elasticsearch-date-histogram/154561/3 "2018-10-30T06:05:37Z")

</div>

Below is the mapping :

```
      {
  "rep_cdr": {
    "aliases": {},
    "mappings": {
      "doc": {
        "dynamic_date_formats": [
          "DD-MM-YYYY",
          "HH:mm:ss",
          "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
        ],
        "properties": {
          "@timestamp": {
            "type": "date",
            "format": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
          },
          "@version": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "TAT": {
            "type": "integer"
          },
          "date": {
            "type": "date",
            "format": "DD-MM-YYYY"
          },
          "level": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "message": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 400
              }
            }
          }
          "reqId": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "response": {
            "type": "keyword"
          },
          "thirdPartyErrorDescription": {
            "type": "text"
          },
          "thirdPartyTime": {
            "type": "integer"
          },
          "time": {
            "type": "date",
            "format": "HH:mm:ss"
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1539236694553",
        "number_of_shards": "3",
        "number_of_replicas": "1",
        "uuid": "BYDQOhY_TbWhuqMAOA3iNw",
        "version": {
          "created": "6040099"
        },
        "provided_name": "rep_cdr"
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 30, 2018, 5:17pm UTC](https://discuss.elastic.co/t/incorrect-month-in-elasticsearch-date-histogram/154561/4 "2018-10-30T17:17:44Z")

</div>

I don't have time yet to reproduce but could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

---

<div class="post-metadata">

**Author:** ![alinaqi306](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@alinaqi306](https://discuss.elastic.co/u/alinaqi306)\
**Post date:** [October 31, 2018, 6:20am UTC](https://discuss.elastic.co/t/incorrect-month-in-elasticsearch-date-histogram/154561/5 "2018-10-31T06:20:39Z")

</div>

@dadoonet thanks for your response. The issue is resolved now.  
I was using DD-MM-YYYY as date format I changed it to dd-MM-yyyy and now it gives correct "key\_as\_string" values.

---

<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:** [November 28, 2018, 6:20am UTC](https://discuss.elastic.co/t/incorrect-month-in-elasticsearch-date-histogram/154561/6 "2018-11-28T06:20:45Z")

</div>

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