0

I'm using terms aggregations with script property, i know that i can use format property to get date value in specific date format; but i wanna write required format to be gotten inside script source code.

{
  "size": 0,
  "aggs": {
    "NAME": {
      "terms": {
        "script": {
          "source": "doc['Ship Date'].value",
          "lang": "painless"
        },
        "size": 100,
        "order": {
          "_key": "asc"
        }
      }
    }
  }
}

1 Answer 1

2

You can do something like below

"size": 0,
  "aggs": {
    "NAME": {
      "terms": {
        "script": {
          "source": "String datetime = 'Thu, 13 Oct 1983 22:15:30 GMT';ZonedDateTime zdt = ZonedDateTime.parse(datetime,DateTimeFormatter.RFC_1123_DATE_TIME); return zdt ",
          "lang": "painless"
        },
        "size": 100,
        "order": {
          "_key": "asc"
        }
      }
    }
  }

You can parse different formats to ZonedDateTime.parse() You can get full detail here

Sign up to request clarification or add additional context in comments.

1 Comment

Glad could be of help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.