# Doc Script Fields - Date Fields outside of index

**URL:** <https://discuss.elastic.co/t/doc-script-fields-date-fields-outside-of-index/32128>\
**Category:** Elasticsearch\
**Created:** [October 14, 2015, 12:02am UTC](https://discuss.elastic.co/t/doc-script-fields-date-fields-outside-of-index/32128 "2015-10-14T00:02:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![s\_used](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@s\_used](https://discuss.elastic.co/u/s_used)\
**Post date:** [October 14, 2015, 12:02am UTC](https://discuss.elastic.co/t/doc-script-fields-date-fields-outside-of-index/32128/1 "2015-10-14T00:02:05Z")

</div>

Hi,

We have a date field called "time\_posted" which is date. Here's our mapping:

> ```
> "time_posted": {
> "type": "date",
> "index": "no",
> "format": "dateOptionalTime",
> "include_in_all": false
> },
> 
> ```

As you can see it is outside of the index. I'm trying to build a script for a field which does some date arithmetic (pretty simple actually, just number of days between the date and now). But having a heck of a time actually retrieving the field as a "doc" field. I've reduced my script down to the following:

```
return doc['time_posted'].empty

```

It returns "true" for every document. However, when I use this as the script, it returns proper dates for each record (but only in string format):

```
  return _source.time_posted 

```

Any idea what is going on? Something to do with my index and/or mapping?

---

<div class="post-metadata">

**Author:** ![s\_used](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@s\_used](https://discuss.elastic.co/u/s_used)\
**Post date:** [October 16, 2015, 3:21pm UTC](https://discuss.elastic.co/t/doc-script-fields-date-fields-outside-of-index/32128/2 "2015-10-16T15:21:02Z")

</div>

Anyone? It seems no matter what I do with that mapping, it wont seem to allow me to use the doc property to retrieve data.

---

<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:** [July 5, 2017, 11:44pm UTC](https://discuss.elastic.co/t/doc-script-fields-date-fields-outside-of-index/32128/3 "2017-07-05T23:44:20Z")

</div>

Closed on July 5, 2017, 11:44pm UTC


