Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Transform advanced editor does not allow you to indent painless #41870

Closed
sophiec20 opened this issue Jul 24, 2019 · 2 comments · Fixed by #58015
Closed

[ML] Transform advanced editor does not allow you to indent painless #41870

sophiec20 opened this issue Jul 24, 2019 · 2 comments · Fixed by #58015
Assignees
Labels
enhancement New value added to drive a business result Feature:Transforms ML transforms :ml usability v7.7.0

Comments

@sophiec20
Copy link
Contributor

sophiec20 commented Jul 24, 2019

Found in 7.3.0-BC5

In Dev tools, you can indent your painless code using a """ notation .. see below for example. However if you try this in the transform advanced editor, you get a red-square-invalid-json warning.. If you remove the indents and convert painless to a single line then it works fine.

For complex scripted fields, it's very useful to be able to indent and space out your painless code. Is it possible to achieve this with the adv json editor?

Example that works in Dev Tools

POST _data_frame/transforms/_preview
{
  "source": {
    "index": "filebeat*"
  },
  "pivot": {
    "group_by": {
      "clientip": {
        "terms": {
          "field": "source.address"
        }
      }
    },
    "aggregations": {
      "responses.total": {
        "value_count": {
          "field": "timestamp"
        }
      },
      "responses.counts": {
        "scripted_metric": {
          "init_script": "state.responses = ['error':0L,'success':0L,'other':0L]",
          "map_script": """
            def code = doc['http.response.status_code'].value;
            if (code.startsWith('5') || code.startsWith('4')) {
              state.responses.error += 1 ;
            } else if(code.startsWith('2')) {
              state.responses.success += 1;
            } else {
              state.responses.other += 1;
            }
            """,
          "combine_script": "state.responses",
          "reduce_script": """
            def counts = ['error': 0L, 'success': 0L, 'other': 0L];
            for (responses in states) {
              counts.error += responses['error'];
              counts.success += responses['success'];
              counts.other += responses['other'];
            }
            return counts;
            """
        }
      }
    }
  }
}
@sophiec20 sophiec20 added enhancement New value added to drive a business result :ml usability Feature:Transforms ML transforms labels Jul 24, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui

@walterra walterra self-assigned this Jul 30, 2019
@walterra walterra removed their assignment Oct 31, 2019
@walterra
Copy link
Contributor

I started a conversation with the Elasticsearch UI team which owns dev console, we'll try to re-use dev console's features so we don't have to re-implemented these features.

@walterra walterra changed the title [ML] Data frame transform advanced editor does not allow you to indent painless [ML] Transform advanced editor does not allow you to indent painless Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Feature:Transforms ML transforms :ml usability v7.7.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants