[DOCS] Fixes getting time features example in Painless in Transforms (#59379)
This commit is contained in:
parent
7dcd943e1d
commit
cdf6a054c6
|
@ -106,7 +106,7 @@ You can retrieve the last value in a similar way:
|
||||||
|
|
||||||
[discrete]
|
[discrete]
|
||||||
[[painless-time-features]]
|
[[painless-time-features]]
|
||||||
==== Getting time features as scripted fields
|
==== Getting time features by using aggregations
|
||||||
|
|
||||||
This snippet shows how to extract time based features by using Painless in a
|
This snippet shows how to extract time based features by using Painless in a
|
||||||
{transform}. The snippet uses an index where `@timestamp` is defined as a `date`
|
{transform}. The snippet uses an index where `@timestamp` is defined as a `date`
|
||||||
|
@ -115,22 +115,22 @@ type field.
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
"aggregations": {
|
"aggregations": {
|
||||||
"script_fields": {
|
"avg_hour_of_day": { <1>
|
||||||
"hour_of_day": { <1>
|
"avg":{
|
||||||
"script": {
|
"script": { <2>
|
||||||
"lang": "painless",
|
|
||||||
"source": """
|
"source": """
|
||||||
ZonedDateTime date = doc['@timestamp'].value; <2>
|
ZonedDateTime date = doc['@timestamp'].value; <3>
|
||||||
return date.getHour(); <3>
|
return date.getHour(); <4>
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"month_of_year": { <4>
|
"avg_month_of_year": { <5>
|
||||||
"script": {
|
"avg":{
|
||||||
"lang": "painless",
|
"script": { <6>
|
||||||
"source": """
|
"source": """
|
||||||
ZonedDateTime date = doc['@timestamp'].value; <5>
|
ZonedDateTime date = doc['@timestamp'].value; <7>
|
||||||
return date.getMonthValue(); <6>
|
return date.getMonthValue(); <8>
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,12 +140,14 @@ type field.
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
// NOTCONSOLE
|
// NOTCONSOLE
|
||||||
|
|
||||||
<1> Contains the Painless script that returns the hour of the day.
|
<1> Name of the aggregation.
|
||||||
<2> Sets `date` based on the timestamp of the document.
|
<2> Contains the Painless script that returns the hour of the day.
|
||||||
<3> Returns the hour value from `date`.
|
<3> Sets `date` based on the timestamp of the document.
|
||||||
<4> Contains the Painless script that returns the month of the year.
|
<4> Returns the hour value from `date`.
|
||||||
<5> Sets `date` based on the timestamp of the document.
|
<5> Name of the aggregation.
|
||||||
<6> Returns the month value from `date`.
|
<6> Contains the Painless script that returns the month of the year.
|
||||||
|
<7> Sets `date` based on the timestamp of the document.
|
||||||
|
<8> Returns the month value from `date`.
|
||||||
|
|
||||||
|
|
||||||
[discrete]
|
[discrete]
|
||||||
|
|
Loading…
Reference in New Issue