-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[DOCS] Refactor script processor docs #72691
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
[DOCS] Refactor script processor docs #72691
Conversation
|
Pinging @elastic/es-core-features (Team:Core/Features) |
|
Pinging @elastic/es-docs (Team:Docs) |
danhermann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks, @jrodewig!
ppf2
left a comment
There was a problem hiding this 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!
jdconrad
left a comment
There was a problem hiding this 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>']` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some notes here:
- 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.
- 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']. - 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.
- 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)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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.
jrodewig
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| -------------------------------------------------- | ||
| [source,console] | ||
| ---- | ||
| POST _ingest/pipeline/_simulate |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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>']` |
There was a problem hiding this comment.
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.
jdconrad
left a comment
There was a problem hiding this 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.
|
Thanks all! |
Changes:
ingestcontext.Closes #72645
Preview
https://elasticsearch_72691.docs-preview.app.elstc.co/guide/en/elasticsearch/reference/master/script-processor.html