Retrieve string date and long date from query result


(Lian) #1

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?


(David Pilato) #2

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.


(Lian) #3

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


(David Pilato) #4

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

It will help to better understand what you are doing.
Please, try to keep the example as simple as possible.


(system) #5

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