vscode-elastic icon indicating copy to clipboard operation
vscode-elastic copied to clipboard

Support multi-line """-separated Painless scripts

Open gabriel-r opened this issue 1 year ago • 2 comments

When the multiline syntax with """ separators is used, the highlighter reports it as an error. Initially I thought it it's just because of the " inside, but it's not (just) that. It seems the highlighter is using JSON rules, while painless is more permissive

This makes it very hard for script editing.

Example code

  "script_fields": {
    "flattened_events": {
      "script": {
        "lang": "painless",
        "source": """
        Map events = new HashMap();
        for (def transaction : doc['external_card_transactions']) {
          Map transData = new HashMap();
          transData.put("created_at", transaction['created_at'].value);
          transData.put("type", transaction['type'].value);
          transData.put("amount", transaction['amount'].value);
          transData.put("currency_code", transaction['currency_code'].value);
          transData.put("original_amount", transaction['currency_conversion.network.original_amount'].value);
          transData.put("original_currency_code", transaction['currency_conversion.network.original_currency_code'].value);
          transData.put("conversion_rate", transaction['currency_conversion.network.conversion_rate'].value);
          events.put(transaction, transData);
        }
        return events.toString();
        """
      }
    }
  },

gabriel-r avatar Dec 05 '23 11:12 gabriel-r

Do you find any alternative to this?

jmarcelomb avatar Apr 03 '25 12:04 jmarcelomb

Do you find any alternative to this?

Nope, I stopped using ES and OS and didn't follow up on this.

gabriel-r avatar Apr 05 '25 22:04 gabriel-r