If condition in scripting

Hello I'm new to painless language, and I don't understand how to exactly to write an if condition.
I want to show the value 1 or 0 in my visualization but the if statement I wrote doesn't seem to work.

{ "script" : {
"lang": "painless",
"source": "if ( (float)doc['field'].value/ 3 >=1 ) ? 1 : 0 ; "
}}

Also what is inline and when to use it ?
Please help me out, I seem to be badly stuck at this.

Thank You

It looks like you are combining an if statement with a ternary -- try removing if and see if your script works.

Inline scripts allow you to define the script in your request directly. The alternative is using stored scripts, and simply referring to them by id in your request. This means you'd be using the _scripts APIs to store the actual script, and then you only need to reference that id elsewhere (and pass params as needed).

@ lukeelmers

Thankyou, I have made similar change and it worked :slight_smile:

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