# Compare between Date Fields

**URL:** <https://discuss.elastic.co/t/compare-between-date-fields/233883>\
**Category:** Elasticsearch\
**Created:** [May 22, 2020, 10:29am UTC](https://discuss.elastic.co/t/compare-between-date-fields/233883 "2020-05-22T10:29:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yummycake](https://avatars.discourse-cdn.com/v4/letter/y/2acd7d/32.png) [@yummycake](https://discuss.elastic.co/u/yummycake)\
**Post date:** [May 22, 2020, 10:29am UTC](https://discuss.elastic.co/t/compare-between-date-fields/233883/1 "2020-05-22T10:29:53Z")

</div>

I am trying to do this get this query  
The Current date is after Current Milestone date it will then give all the documents in the index.

Here is my current query

```auto
GET /my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "script": {
            "script": "doc['Current_Date'].date.isAfter(doc['Current Milestone'].date)"
          }
        }
      ]
    }
  }
}

```

But I got this error

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

```

Anyone care to help? I have tried .value still fails

---

<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:** [June 19, 2020, 10:30am UTC](https://discuss.elastic.co/t/compare-between-date-fields/233883/2 "2020-06-19T10:30:03Z")

</div>

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