0

I'm using the latest version of elasticsearch npm with elasticsearch version 6.4 and trying to put new script.

According to thier documentation; putScript function takes id and body properties.

So when i try to call it, for instance:

client.putScript({
    id: 'date_formatter',
    body: {
        lang: "painless",
        source: `// Get each field value as string
            String datetime = doc[params.field].value.toString();
            // Create format object based on string
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(params.format);
            // cast datetime into ZonedDateTime to use format function
            ZonedDateTime zdt = ZonedDateTime.parse(datetime);
            // return formatted date
            return zdt.format(formatter);`
    }
})

It returns { acknowledged: true } as expected, But when i check it through kibana, it returns:

{
  "_id": "date_formatter",
  "found": true,
  "script": {
    "lang": "mustache",
    "source": """{"lang":"painless"}"""
  }
}

Is there any way to put script into elasticsearch through node client?

2
  • There's a typo land should read lang Commented Oct 1, 2019 at 11:26
  • Still not working Commented Oct 1, 2019 at 11:39

1 Answer 1

1

You need to wrap both lang and source into a script section basically the same way as described here:

client.putScript({
    id: 'date_formatter',
    body: {
        script: {
            lang: "painless",
            source: `// Get each field value as string
                String datetime = doc[params.field].value.toString();
                // Create format object based on string
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern(params.format);
                // cast datetime into ZonedDateTime to use format function
                ZonedDateTime zdt = ZonedDateTime.parse(datetime);
                // return formatted date
                return zdt.format(formatter);`
            }
        }
    })
Sign up to request clarification or add additional context in comments.

Comments

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.