Specify format in sort query

(Animageofmine) #1

I have a query, where someDate is of type date. I don't have control over mapping while creating an index. I wanted to get the value in millis for the following query. Is there a way to do that in ES (via API)

GET /myindex/_search
    "size": 1,
    "sort": [
        { "someDate": {"order": "asc"},
          "format": "epoch_millis" // this does not seem to be supported in ES 5.4

The actual response looks like this:

"SomeDate": "2017-08-01T01:07:04.000Z"

I would like to get the following response

"SomeDate": 1501636024000

(Zachary Tong) #2

I'd probably use a script_field to do this.

Script fields basically execute an arbitrary script for each hit, and the script's return value is used to create a "virtual" field on the document. So you could use the script field to generate a "formattedDate" field which has the formatting you desire.

(system) #3

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