Skip to content

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

Closed
wants to merge 3 commits into from
Closed

Conversation

jdconrad
Copy link
Contributor

This adds a reindex example to extend the existing ingest example under the documentation for script contexts within Painless.

@jdconrad jdconrad added >docs General docs changes :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache v7.0.0 v6.5.0 labels Sep 25, 2018
@jdconrad jdconrad requested a review from debadair September 25, 2018 02:10
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@jdconrad jdconrad mentioned this pull request Sep 25, 2018
22 tasks

The example reindex script accomplishes the following:

Copy link
Contributor

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
Copy link
Contributor

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>>.

Copy link
Contributor

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:

Copy link
Contributor

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:
+
Copy link
Contributor

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::
Copy link
Contributor

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).

@colings86 colings86 added v6.6.0 and removed v6.5.0 labels Oct 25, 2018
@jdconrad jdconrad mentioned this pull request Oct 26, 2018
17 tasks
@jasontedor jasontedor added v6.7.0 and removed v6.6.0 labels Dec 19, 2018
@jasontedor jasontedor added v8.0.0 and removed v7.0.0 labels Feb 6, 2019
@jdconrad
Copy link
Contributor Author

I'm closing this as this needs to be re-worked heavily at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >docs General docs changes v8.0.0-alpha1 WIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants