AntonShuvaev / elasticsearch4idea

Elasticsearch Plugin for JetBrains IDEs
https://plugins.jetbrains.com/plugin/14512-elasticsearch
59 stars 8 forks source link

Multi-line scripts not supported like in Kibana #66

Closed sbritocorral closed 2 years ago

sbritocorral commented 2 years ago

Hi @AntonShuvaev,

First of all, I have to say great work. I really like your plugin.

I have one issue with multi-line scripts. For maintaining long scripts is deemed necessary to use multi-line scripts for easier visualization. It would great to support multi-line scripts in the plugin. E.g following script is not supported, but works perfectly in Kibana.

POST _scripts/clean-old-profiles
{
  "script": {
    "lang": "painless",
    "source": """
          void iterateAllFields(def x) {
             if (x instanceof List) {
               for (def v: x) {
                 iterateAllFields(v);
               }
             }
             if (!(x instanceof Map)) {
               return;
             }
             x.entrySet().removeIf(e -> (e.getValue() == "" || e.getValue() == null || ((e.getValue() instanceof List || e.getValue() instanceof Map) && e.getValue().isEmpty())));
             for (def v: x.values()) {
               iterateAllFields(v);
             }
           }

          ctx.following = null;
          ctx.ims = null;
          ctx.products = null;

          iterateAllFields(ctx);

          if (ctx.languages != null) {
              for(item in ctx.languages) {
                   item.remove('isProfileLanguage');
              }
          }
          if (ctx.emails != null) {
              for(item in ctx.emails) {
                   item.remove('probability');
              }
          }
          """
  }
}
AntonShuvaev commented 2 years ago

Good suggestion! I will consider adding this in the future update.

AntonShuvaev commented 2 years ago

Supported in 2022.1.3.