# ZoneDataTime error on query but not injest for pipeline

**URL:** <https://discuss.elastic.co/t/zonedatatime-error-on-query-but-not-injest-for-pipeline/204110>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [October 17, 2019, 5:51pm UTC](https://discuss.elastic.co/t/zonedatatime-error-on-query-but-not-injest-for-pipeline/204110 "2019-10-17T17:51:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlaprade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dlaprade/32/47576_2.png) [@dlaprade](https://discuss.elastic.co/u/dlaprade)\
**Post date:** [October 17, 2019, 5:51pm UTC](https://discuss.elastic.co/t/zonedatatime-error-on-query-but-not-injest-for-pipeline/204110/1 "2019-10-17T17:51:51Z")

</div>

Elasticsearch version tested:

- 7.1.1
- 7.2.0

Index mapping field:

```
 "releaseDate" : {
                     "type" : "date",
                     "format" : "yyyy-MM-dd'T'HH:mm:ssXXX"
                 },

```

Pipeline:

```
{
    "processors": [
      {
        "script": {
          "lang": "painless",
          "source": "ctx.releaseYear = ZonedDateTime.parse(ctx.releaseDate,DateTimeFormatter.ISO_DATE_TIME).getYear()"
        }
      }
    ]
}

```

Problem:

I create a new index that contains the above 'releaseDate' field and re-index data into it without any problems. When I do a generic search, I can see the new field 'releaseYear' in my results. When I do a more complex query that uses the 'releaseDate' field, I am getting an error:

```
{
    "error": {
        "root_cause": [
            {
                "type": "script_exception",
                "reason": "runtime error",
                "script_stack": [
                    "doc['releaseDate'].date.getYear()",
                    " ^---- HERE"
                ],
                "script": "doc['releaseDate'].date.getYear()",
                "lang": "painless"
            }
        ],
        "type": "search_phase_execution_exception",
        "reason": "all shards failed",
        "phase": "query",
        "grouped": true,
        "failed_shards": [
            {
                "shard": 0,
                "index": "generic_v1",
                "node": "CV44lJMOR-et8cdYzRb5bQ",
                "reason": {
                    "type": "script_exception",
                    "reason": "runtime error",
                    "script_stack": [
                        "doc['releaseDate'].date.getYear()",
                        " ^---- HERE"
                    ],
                    "script": "doc['releaseDate'].date.getYear()",
                    "lang": "painless",
                    "caused_by": {
                        "type": "illegal_argument_exception",
                        "reason": "Illegal list shortcut value [date]."
                    }
                }
            }
        ]
    },
    "status": 400

```

> }

From search query:

```
{
  "from": 0,
  "size": 25,
  "sort": [
    {
      "releaseDate": {
        "order": "desc"
      }
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "releaseDate": {
              "lte": "now"
            }
          }
        }
      ]
    }
  }
}

```

Any ideas what I might be doing wrong?

---

<div class="post-metadata">

**Author:** ![dlaprade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dlaprade/32/47576_2.png) [@dlaprade](https://discuss.elastic.co/u/dlaprade)\
**Post date:** [October 17, 2019, 9:55pm UTC](https://discuss.elastic.co/t/zonedatatime-error-on-query-but-not-injest-for-pipeline/204110/2 "2019-10-17T21:55:55Z")

</div>

After further investigations, I found that the error is being caused by an aggregation in my query:

```
"aggs" : {
"years": {
      "histogram": {
        "script": "doc['releaseDate'].date.getYear()",
        "interval": 1,
        "min_doc_count": 1,
        "order": {
          "_term": "asc"
        }
      }
    }
}
```

---

<div class="post-metadata">

**Author:** ![dlaprade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dlaprade/32/47576_2.png) [@dlaprade](https://discuss.elastic.co/u/dlaprade)\
**Post date:** [October 17, 2019, 10:06pm UTC](https://discuss.elastic.co/t/zonedatatime-error-on-query-but-not-injest-for-pipeline/204110/3 "2019-10-17T22:06:06Z")

</div>

I was able to fix my issue by updating my aggregation to be like:

```
"years": {
      "terms": {
        "field": "releaseYear",
        "size": "100000",
        "order": {
          "_key": "asc"
        }
      }
    },

```

and use the new field that is created by the pipeline.

---

<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 14, 2019, 10:06pm UTC](https://discuss.elastic.co/t/zonedatatime-error-on-query-but-not-injest-for-pipeline/204110/4 "2019-11-14T22:06:06Z")

</div>

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