Skip to content

Conversation

@jrodewig
Copy link
Contributor

@jrodewig jrodewig commented May 4, 2021

Changes:

  • Updates the intro link for scripts and the ingest context.
  • Rewrites the options section to better align with the create stored script API docs.
  • Updates the examples to provide more realistic examples and use the simulate pipeline API.

Closes #72645

Preview

https://elasticsearch_72691.docs-preview.app.elstc.co/guide/en/elasticsearch/reference/master/script-processor.html

@jrodewig jrodewig added :Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP >docs General docs changes v7.12.2 v7.13.1 v7.14.0 v8.0.0 labels May 4, 2021
@jrodewig jrodewig marked this pull request as ready for review May 4, 2021 15:26
@elasticmachine elasticmachine added Team:Data Management Meta label for data/management team Team:Docs Meta label for docs team labels May 4, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features (Team:Core/Features)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-docs (Team:Docs)

@jrodewig jrodewig requested review from danhermann and jdconrad May 4, 2021 15:26
@jrodewig jrodewig requested a review from ppf2 May 4, 2021 15:29
Copy link
Contributor

@danhermann danhermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks, @jrodewig!

Copy link
Contributor

@ppf2 ppf2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thx for addressing this confusion!

Copy link
Contributor

@jdconrad jdconrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating these docs! This is a solid improvement. I have a few requests including a couple of minor corrections.

| Name | Required | Default | Description
| `lang` | no | "painless" | <<scripting-available-languages,Script language>>.
| `id` | no | - | ID of a <<create-stored-script-api,stored script>>.
If no `source` is specified, this parameter is required.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's confusing to have this table say 'no' to all parameters in an either/or situation. One of id/source is required, and while this is specified as part of the description, is there a way we could change the no to a '*' or some other indicator that at least one of these is required because it's easy to miss on quick glance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this isn't ideal, but it's consistent with the other ingest processors. Changing this would break the later include::common-options.asciidoc[] statement, which is used in all our processor reference docs.

I've opened #72717 to address your concerns as a separate effort.


You can access the current ingest document from within the script context by using the `ctx` variable.
To access an incoming document's source fields with a Painless script, use the
`ctx.<field>` syntax. The `ctx._source.<field>` and `ctx['_source.<field>']`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes here:

  1. I would include a bit more detail about how the documents contents are a set of maps, lists, and primitives based on the parsed JSON from the original source document.
  2. I wonder if the not included should be a note section to isolate that. I initially read that as I can use ctx._source because the not supported is at the end of the sentence. ctx['_source.<field>'] should be ctx['_source']['my_field'].
  3. I would prefer to present the appropriate way to access fields as ctx['my_field'] instead of ctx.my_field since the first way can allow any field with special characters, but the second way is just a limited shortcut.
  4. It may be worth having a link to the access operator here. (https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-operators-reference.html#map-access-operator)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this feedback. I pushed 9a1f779 to update this section and use the preferred syntax.

--------------------------------------------------
[source,console]
----
POST _ingest/pipeline/_simulate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we explain what the simulate query is anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's covered in the ingest pipeline docs. I don't feel we need to cover that here.

"description": "Extract 'tags' from 'env' field",
"lang": "painless",
"source": """
String[] envSplit = ctx?.env.splitOnToken(params.delimiter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a case where ctx can actually be null? Also we still access envSplit anyway so if ctx were null this is still going to throw an NPE. I would not include the elvis operator here.
ctx?.env.splitOnToken(params.delimiter); --> ctx.env.splitOnToken(params.delimiter);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I've changed this to remove the shorthand syntax anyway.

Copy link
Contributor Author

@jrodewig jrodewig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @jdconrad. I've responded to your comments and pushed 9a1f779 to address your feedback.

--------------------------------------------------
[source,console]
----
POST _ingest/pipeline/_simulate
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's covered in the ingest pipeline docs. I don't feel we need to cover that here.

| Name | Required | Default | Description
| `lang` | no | "painless" | <<scripting-available-languages,Script language>>.
| `id` | no | - | ID of a <<create-stored-script-api,stored script>>.
If no `source` is specified, this parameter is required.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this isn't ideal, but it's consistent with the other ingest processors. Changing this would break the later include::common-options.asciidoc[] statement, which is used in all our processor reference docs.

I've opened #72717 to address your concerns as a separate effort.

"description": "Extract 'tags' from 'env' field",
"lang": "painless",
"source": """
String[] envSplit = ctx?.env.splitOnToken(params.delimiter);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I've changed this to remove the shorthand syntax anyway.


You can access the current ingest document from within the script context by using the `ctx` variable.
To access an incoming document's source fields with a Painless script, use the
`ctx.<field>` syntax. The `ctx._source.<field>` and `ctx['_source.<field>']`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this feedback. I pushed 9a1f779 to update this section and use the preferred syntax.

@jrodewig jrodewig requested a review from jdconrad May 4, 2021 19:09
Copy link
Contributor

@jdconrad jdconrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for updating this.

@jrodewig
Copy link
Contributor Author

jrodewig commented May 4, 2021

Thanks all!

@jrodewig jrodewig merged commit bd84e8a into elastic:master May 4, 2021
@jrodewig jrodewig deleted the docs__fix-script-processor-docs branch May 4, 2021 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP >docs General docs changes Team:Data Management Meta label for data/management team Team:Docs Meta label for docs team v7.12.2 v7.13.0 v7.14.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Script processor doc links to update API examples which is confusing

7 participants