# Retrieve string date and long date from query result

**URL:** https://discuss.elastic.co/t/retrieve-string-date-and-long-date-from-query-result/104043
**Category:** Elasticsearch
**Created:** [October 16, 2017, 3:53am UTC](https://discuss.elastic.co/t/retrieve-string-date-and-long-date-from-query-result/104043 "2017-10-16T03:53:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Lian](https://avatars.discourse-cdn.com/v4/letter/l/919ad9/32.png) [@Lian](https://discuss.elastic.co/u/Lian)
#### Post date: [October 16, 2017, 3:53am UTC](https://discuss.elastic.co/t/retrieve-string-date-and-long-date-from-query-result/104043/1 "2017-10-16T03:53:47Z")

</div>

I have a date field defined in index as

```
    "_reportDate": {
                    "type": "date",
                    "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
                }

```

and I have a query to query from \_source field which gives \_reportDate field in string of 2015-12-05 01:05:00.

I can't seems to find a way to get date in different date format during query retrieval apart from using script field (which is not preferable). From what I understand a date field will be parse to long value to be indexed in elastic search, can we retrieve the long value as well during elasticsearch query?

---

<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 16, 2017, 5:17am UTC](https://discuss.elastic.co/t/retrieve-string-date-and-long-date-from-query-result/104043/2 "2017-10-16T05:17:21Z")

</div>

You need to store the field and at search time ask for this stored field.

If it does not work you can always apply the script at index time with ingest feature and a script processor.

---

<div class="post-metadata">

### Author: ![Lian](https://avatars.discourse-cdn.com/v4/letter/l/919ad9/32.png) [@Lian](https://discuss.elastic.co/u/Lian)
#### Post date: [October 16, 2017, 7:03am UTC](https://discuss.elastic.co/t/retrieve-string-date-and-long-date-from-query-result/104043/3 "2017-10-16T07:03:11Z")

</div>

Thanks for info, I just try with the store fields but it does not work when I search for the docs with the field specified. Currently I am using version 2.4, I guess I will format the date in front-end/server-end to resolve my problem

---

<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 16, 2017, 7:19am UTC](https://discuss.elastic.co/t/retrieve-string-date-and-long-date-from-query-result/104043/4 "2017-10-16T07:19:35Z")

</div>

> I guess I will format the date in front-end/server-end to resolve my problem

Probably easier indeed.

> it does not work when I search for the docs with the field specified.

If you want to go further, may be provide a full recreation script as described in

> [@About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21):
>
> The heart of the free and open Elastic Stack Elasticsearch is a distributed, RESTful search and analytics engine capable of addressing a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data for lightning fast search, fine‑tuned relevancy, and powerful analytics that scale with ease. warning PLEASE READ THIS SECTION IF IT'S YOUR FIRST POST Some useful links: [elasticsearch reference guide](http://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)[elasticsearch user guide](http://www.elastic.co/guide/en/elasticsearch/guide/current/index.html)[elasticsearch plugins](https://www.elastic.co/guide/en/elasticsearch/plugins/current/index.html)[elasticsearch cl…](https://www.elastic.co/guide/en/elasticsearch/client/index.html)

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: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 13, 2017, 7:20am UTC](https://discuss.elastic.co/t/retrieve-string-date-and-long-date-from-query-result/104043/5 "2017-11-13T07:20:07Z")

</div>

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