-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Painless: Add reindex docs example #34024
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
Conversation
Pinging @elastic/es-core-infra |
|
||
The example reindex script accomplishes the following: | ||
|
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'd just say, "This example:"
* Separates the `seats` index into two different new indexes - `afternoon` and | ||
`evening` based on when a play begins. | ||
* Removes the `date` and `time` fields that are extraneous since the |
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.
Missing a - after evening. (I'd be inclined to use commas.)
To run this example, first follow the steps in | ||
<<painless-context-examples, context examples>>. | ||
|
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'd mention that other samples build on this one here, rather than as part of what this example does. Maybe just, "The afternoon
and evening
indices created by this script are used in other examples." I'd probably also move this notice below the example & its description, just before the instructions to set the mappings & call reindex.
|
||
Submit the following requests: | ||
|
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.
Instead of "Submit the following requests" I'd say "To use this script to reindex the seats
index:"
`evening` index has 17892 documents. Submit the following request to check the | ||
number of documents in each index: | ||
+ |
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 wouldn't make this a step. I'd drop the "Submit the following request" and just say, "You can use _cat/indices
to check the number of documents in each index:"
<1> Creates a `setSold` <<painless-functions, function>> to set a seat to sold | ||
if it meets certain criteria for use in future examples. | ||
Note:: |
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'd drop the "for use in future examples" and say "...to mark a seat as sold if it meets certain criteria."
Instead of a callout for every line, I'd be inclined to break this info out into more of a narrative.
In this reindex script, the setSold
<<painless-functions, function>> marks a seat as sold if it meets certain criteria. The seat number and row are extracted from the source to perform the evaluation. To mark a seat sold, the sold
field is set to the boolean value true
and sold_datetime
is set to an arbitrary value up to 15 days prior to the document's datetime
value. When setting sold_datetime
, the <<precedence-operator, precedence operator>> is used to guarantee that the number of days in the equation is evaluated prior to subtracting the number of seconds from the play's date and time.
NOTE: The changes to the _source
Map
type value that's passed in to setSold
are reflected throughout the script since it's a <<reference-types, reference type>> value.
The removeExtraneous
function removes the redundant date
and time
fields from the document source.
When these functions are called, the ctx["_source"]
reindex context variable is used to retrieve the Map
reference type value that contains the document's fields.
To determine if the seat should be added to the evening
index or the default afternoon
index, the script:
. Converts the datetime
value from a <<primitive-types, long
>> type to an Instant
reference type by calling the API static method ofEpochMilli
.
. Converts the instant
value to the DateTime
reference type using the API static method atZone
. The time zone is specified using the API static method of
on the reference type ZoneId
.
. Calls getHour
to get the hour from the DateTime value and checks to see if it's past 4:00PM GMT+8 (PST)
.
I'm closing this as this needs to be re-worked heavily at this point. |
This adds a reindex example to extend the existing ingest example under the documentation for script contexts within Painless.