0

I have date with this format November 17th 2016, 12:54:29.000" and I need to get that 17 only using painless script. Also if anyone can provide me link to painless script tutorial regarding date formats.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Saurab
  • 1,931
  • 5
  • 20
  • 33

1 Answers1

4

If the field is mapped as date you can just

doc['<field_name>'].date.dayOfMonth.

Otherwise, you'll need to use a regular expression, something like

/ (\d{2})/.matcher(doc['<field_name>'].value).group(1).

The date-based solution uses org.joda.time.MutableDateTime. The regex one uses java.util.regex.Matcher and you have to enable regular expressions in your Elasticsearch configuration file as script.painless.regex.enabled=on.

mmas
  • 78
  • 1
  • 6