Skip to content

Make dates be ReadableDateTimes in scripts#22948

Merged
nik9000 merged 2 commits intoelastic:masterfrom
nik9000:script_doc_values_for_dates
Feb 6, 2017
Merged

Make dates be ReadableDateTimes in scripts#22948
nik9000 merged 2 commits intoelastic:masterfrom
nik9000:script_doc_values_for_dates

Conversation

@nik9000
Copy link
Copy Markdown
Member

@nik9000 nik9000 commented Feb 3, 2017

Instead of longs. If you want millis since epoch you can call doc.date_field.value.millis.

Relates to #22875

@nik9000 nik9000 added :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >breaking >enhancement v6.0.0-alpha1 labels Feb 3, 2017
@nik9000 nik9000 requested a review from rjernst February 3, 2017 02:23
@nik9000
Copy link
Copy Markdown
Member Author

nik9000 commented Feb 3, 2017

@rjernst, would you like to look at this? It is the second step we discussed in #22875 (comment).

Copy link
Copy Markdown
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

LGTM

// that scripts return the same internal representation as regular fields, so boolean
// values in scripts need to be converted to a number, and the value formatter will
// make sure of using true/false in the key_as_string field
return ((Boolean) o).booleanValue() ? 1.0 : 0.0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is just a bonus fix, unrelated to the date change right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Indeed - bonus to make this line up with toLongValue.


==== Date fields now return dates

`doc.some_date_field.value` now returns `ReadableDateTime`s instead of
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it possible to link ReadableDateTime here to the generated painless docs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure!

Copy link
Copy Markdown
Member Author

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

Given this conversation I don't think we're done here but I still think this is a step in the right direction so I'm going to retest locally and merge.

// that scripts return the same internal representation as regular fields, so boolean
// values in scripts need to be converted to a number, and the value formatter will
// make sure of using true/false in the key_as_string field
return ((Boolean) o).booleanValue() ? 1.0 : 0.0;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Indeed - bonus to make this line up with toLongValue.


==== Date fields now return dates

`doc.some_date_field.value` now returns `ReadableDateTime`s instead of
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure!

@nik9000 nik9000 merged commit 0d6e622 into elastic:master Feb 6, 2017
@nik9000
Copy link
Copy Markdown
Member Author

nik9000 commented Feb 6, 2017

master: 0d6e622

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>breaking :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >enhancement v6.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants