mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
improve date api for expressions/painless fields
This commit is contained in:
parent
502a775a7c
commit
2d1eb89aef
16 changed files with 467 additions and 37 deletions
|
@ -42,6 +42,8 @@ scripts, simply set the `lang` parameter to `expression`.
|
|||
|`doc['field_name'].empty` |A boolean indicating if the field has no
|
||||
values within the doc.
|
||||
|
||||
|`doc['field_name'].length` |The number of values in this document.
|
||||
|
||||
|`doc['field_name'].min()` |The minimum value of the field in this document.
|
||||
|
||||
|`doc['field_name'].max()` |The maximum value of the field in this document.
|
||||
|
@ -51,8 +53,6 @@ values within the doc.
|
|||
|`doc['field_name'].avg()` |The average of the values in this document.
|
||||
|
||||
|`doc['field_name'].sum()` |The sum of the values in this document.
|
||||
|
||||
|`doc['field_name'].count()` |The number of values in this document.
|
||||
|=======================================================================
|
||||
|
||||
When a document is missing the field completely, by default the value will be treated as `0`.
|
||||
|
@ -69,27 +69,47 @@ For example: `doc['on_sale'].value ? doc['price'].value * 0.5 : doc['price'].val
|
|||
[float]
|
||||
=== Date field API
|
||||
Date fields are treated as the number of milliseconds since January 1, 1970 and
|
||||
support the Numeric Fields API above, with these additional methods:
|
||||
support the Numeric Fields API above, plus access to some date-specific fields:
|
||||
|
||||
[cols="<,<",options="header",]
|
||||
|=======================================================================
|
||||
|Expression |Description
|
||||
|`doc['field_name'].getYear()` |Year component, e.g. `1970`.
|
||||
|`doc['field_name'].date.centuryOfEra`|Century (1-2920000)
|
||||
|
||||
|`doc['field_name'].getMonth()` |Month component (0-11), e.g. `0` for January.
|
||||
|`doc['field_name'].date.dayOfMonth`|Day (1-31), e.g. `1` for the first of the month.
|
||||
|
||||
|`doc['field_name'].getDayOfMonth()` |Day component, e.g. `1` for the first of the month.
|
||||
|`doc['field_name'].date.dayOfWeek`|Day of the week (1-7), e.g. `1` for Monday.
|
||||
|
||||
|`doc['field_name'].getHourOfDay()` |Hour component (0-23)
|
||||
|`doc['field_name'].date.dayOfYear`|Day of the year, e.g. `1` for January 1.
|
||||
|
||||
|`doc['field_name'].getMinutes()` |Minutes component (0-59)
|
||||
|`doc['field_name'].date.era`|Era: `0` for BC, `1` for AD.
|
||||
|
||||
|`doc['field_name'].getSeconds()` |Seconds component (0-59)
|
||||
|`doc['field_name'].date.hourOfDay`|Hour (0-23).
|
||||
|
||||
|`doc['field_name'].date.millisOfDay`|Milliseconds within the day (0-86399999).
|
||||
|
||||
|`doc['field_name'].date.millisOfSecond`|Milliseconds within the second (0-999).
|
||||
|
||||
|`doc['field_name'].date.minuteOfDay`|Minute within the day (0-1439).
|
||||
|
||||
|`doc['field_name'].date.minuteOfHour`|Minute within the hour (0-59).
|
||||
|
||||
|`doc['field_name'].date.monthOfYear`|Month within the year (1-12), e.g. `1` for January.
|
||||
|
||||
|`doc['field_name'].date.secondOfDay`|Second within the day (0-86399).
|
||||
|
||||
|`doc['field_name'].date.secondOfMinute`|Second within the minute (0-59).
|
||||
|
||||
|`doc['field_name'].date.year`|Year (-292000000 - 292000000).
|
||||
|
||||
|`doc['field_name'].date.yearOfCentury`|Year within the century (1-100).
|
||||
|
||||
|`doc['field_name'].date.yearOfEra`|Year within the era (1-292000000).
|
||||
|=======================================================================
|
||||
|
||||
The following example shows the difference in years between the `date` fields date0 and date1:
|
||||
|
||||
`doc['date1'].getYear() - doc['date0'].getYear()`
|
||||
`doc['date1'].date.year - doc['date0'].date.year`
|
||||
|
||||
[float]
|
||||
=== `geo_point` field API
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue