|
@@ -459,9 +459,9 @@ source document is most commonly accessible through an input called
|
|
|
[source,JSON]
|
|
|
----
|
|
|
{
|
|
|
- ...
|
|
|
- "input_datetime": 434931327000
|
|
|
- ...
|
|
|
+ ...
|
|
|
+ "input_datetime": 434931327000
|
|
|
+ ...
|
|
|
}
|
|
|
----
|
|
|
+
|
|
@@ -482,9 +482,9 @@ ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, ZoneId.of('Z'));
|
|
|
[source,JSON]
|
|
|
----
|
|
|
{
|
|
|
- ...
|
|
|
- "input_datetime": "1983-10-13T22:15:30Z"
|
|
|
- ...
|
|
|
+ ...
|
|
|
+ "input_datetime": "1983-10-13T22:15:30Z"
|
|
|
+ ...
|
|
|
}
|
|
|
----
|
|
|
+
|
|
@@ -523,17 +523,17 @@ document is most commonly accessible through an input called `doc`.
|
|
|
[source,JSON]
|
|
|
----
|
|
|
{
|
|
|
- "mappings": {
|
|
|
- ...
|
|
|
- "properties": {
|
|
|
- ...
|
|
|
- "input_datetime": {
|
|
|
- "type": "date"
|
|
|
- }
|
|
|
- ...
|
|
|
- }
|
|
|
- ...
|
|
|
+ "mappings": {
|
|
|
+ ...
|
|
|
+ "properties": {
|
|
|
+ ...
|
|
|
+ "input_datetime": {
|
|
|
+ "type": "date"
|
|
|
+ }
|
|
|
+ ...
|
|
|
}
|
|
|
+ ...
|
|
|
+ }
|
|
|
}
|
|
|
----
|
|
|
+
|
|
@@ -559,20 +559,20 @@ query
|
|
|
[source,JSON]
|
|
|
----
|
|
|
{
|
|
|
- "mappings": {
|
|
|
- ...
|
|
|
- "properties": {
|
|
|
- ...
|
|
|
- "start": {
|
|
|
- "type": "date"
|
|
|
- },
|
|
|
- "end": {
|
|
|
- "type": "date"
|
|
|
- }
|
|
|
- ...
|
|
|
- }
|
|
|
- ...
|
|
|
+ "mappings": {
|
|
|
+ ...
|
|
|
+ "properties": {
|
|
|
+ ...
|
|
|
+ "start": {
|
|
|
+ "type": "date"
|
|
|
+ },
|
|
|
+ "end": {
|
|
|
+ "type": "date"
|
|
|
+ }
|
|
|
+ ...
|
|
|
}
|
|
|
+ ...
|
|
|
+ }
|
|
|
}
|
|
|
----
|
|
|
+
|
|
@@ -627,17 +627,17 @@ preferred as there is no need to parse it for comparison.
|
|
|
[source,JSON]
|
|
|
----
|
|
|
{
|
|
|
- "mappings": {
|
|
|
- ...
|
|
|
- "properties": {
|
|
|
- ...
|
|
|
- "input_datetime": {
|
|
|
- "type": "date"
|
|
|
- }
|
|
|
- ...
|
|
|
- }
|
|
|
+ "mappings": {
|
|
|
+ ...
|
|
|
+ "properties": {
|
|
|
...
|
|
|
+ "input_datetime": {
|
|
|
+ "type": "date"
|
|
|
+ }
|
|
|
+ ...
|
|
|
}
|
|
|
+ ...
|
|
|
+ }
|
|
|
}
|
|
|
----
|
|
|
+
|
|
@@ -677,17 +677,17 @@ long elapsedTime = now - millisDateTime;
|
|
|
[source,JSON]
|
|
|
----
|
|
|
{
|
|
|
- "mappings": {
|
|
|
- ...
|
|
|
- "properties": {
|
|
|
- ...
|
|
|
- "input_datetime": {
|
|
|
- "type": "date"
|
|
|
- }
|
|
|
- ...
|
|
|
- }
|
|
|
- ...
|
|
|
+ "mappings": {
|
|
|
+ ...
|
|
|
+ "properties": {
|
|
|
+ ...
|
|
|
+ "input_datetime": {
|
|
|
+ "type": "date"
|
|
|
+ }
|
|
|
+ ...
|
|
|
}
|
|
|
+ ...
|
|
|
+ }
|
|
|
}
|
|
|
----
|
|
|
+
|
|
@@ -732,19 +732,19 @@ examples into an Elasticsearch cluster:
|
|
|
----
|
|
|
PUT /messages
|
|
|
{
|
|
|
- "mappings": {
|
|
|
- "properties": {
|
|
|
- "priority": {
|
|
|
- "type": "integer"
|
|
|
- },
|
|
|
- "datetime": {
|
|
|
- "type": "date"
|
|
|
- },
|
|
|
- "message": {
|
|
|
- "type": "text"
|
|
|
- }
|
|
|
- }
|
|
|
+ "mappings": {
|
|
|
+ "properties": {
|
|
|
+ "priority": {
|
|
|
+ "type": "integer"
|
|
|
+ },
|
|
|
+ "datetime": {
|
|
|
+ "type": "date"
|
|
|
+ },
|
|
|
+ "message": {
|
|
|
+ "type": "text"
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
----
|
|
|
+
|
|
@@ -788,13 +788,13 @@ display the number of messages from each day-of-the-week.
|
|
|
----
|
|
|
GET /messages/_search?pretty=true
|
|
|
{
|
|
|
- "aggs": {
|
|
|
- "day-of-week-count": {
|
|
|
- "terms": {
|
|
|
- "script": "return doc[\"datetime\"].value.getDayOfWeekEnum();"
|
|
|
- }
|
|
|
- }
|
|
|
+ "aggs": {
|
|
|
+ "day-of-week-count": {
|
|
|
+ "terms": {
|
|
|
+ "script": "return doc[\"datetime\"].value.getDayOfWeekEnum();"
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
----
|
|
|
// TEST[continued]
|
|
@@ -811,13 +811,13 @@ display the number of messages received in the morning versus the evening.
|
|
|
----
|
|
|
GET /messages/_search?pretty=true
|
|
|
{
|
|
|
- "aggs": {
|
|
|
- "am-pm-count": {
|
|
|
- "terms": {
|
|
|
- "script": "return doc[\"datetime\"].value.getHour() < 12 ? \"AM\" : \"PM\";"
|
|
|
- }
|
|
|
- }
|
|
|
+ "aggs": {
|
|
|
+ "am-pm-count": {
|
|
|
+ "terms": {
|
|
|
+ "script": "return doc[\"datetime\"].value.getHour() < 12 ? \"AM\" : \"PM\";"
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
----
|
|
|
// TEST[continued]
|
|
@@ -833,19 +833,19 @@ The following example uses a
|
|
|
----
|
|
|
GET /_search?pretty=true
|
|
|
{
|
|
|
- "query" : {
|
|
|
- "match_all": {}
|
|
|
- },
|
|
|
- "script_fields" : {
|
|
|
- "message_age" : {
|
|
|
- "script" : {
|
|
|
- "source": "ZonedDateTime now = ZonedDateTime.ofInstant(Instant.ofEpochMilli(params[\"now\"]), ZoneId.of(\"Z\")); ZonedDateTime mdt = doc[\"datetime\"].value; String age; long years = mdt.until(now, ChronoUnit.YEARS); age = years + \"Y \"; mdt = mdt.plusYears(years); long months = mdt.until(now, ChronoUnit.MONTHS); age += months + \"M \"; mdt = mdt.plusMonths(months); long days = mdt.until(now, ChronoUnit.DAYS); age += days + \"D \"; mdt = mdt.plusDays(days); long hours = mdt.until(now, ChronoUnit.HOURS); age += hours + \"h \"; mdt = mdt.plusHours(hours); long minutes = mdt.until(now, ChronoUnit.MINUTES); age += minutes + \"m \"; mdt = mdt.plusMinutes(minutes); long seconds = mdt.until(now, ChronoUnit.SECONDS); age += hours + \"s\"; return age;",
|
|
|
- "params": {
|
|
|
- "now": 1574005645830
|
|
|
- }
|
|
|
- }
|
|
|
+ "query": {
|
|
|
+ "match_all": {}
|
|
|
+ },
|
|
|
+ "script_fields": {
|
|
|
+ "message_age": {
|
|
|
+ "script": {
|
|
|
+ "source": "ZonedDateTime now = ZonedDateTime.ofInstant(Instant.ofEpochMilli(params[\"now\"]), ZoneId.of(\"Z\")); ZonedDateTime mdt = doc[\"datetime\"].value; String age; long years = mdt.until(now, ChronoUnit.YEARS); age = years + \"Y \"; mdt = mdt.plusYears(years); long months = mdt.until(now, ChronoUnit.MONTHS); age += months + \"M \"; mdt = mdt.plusMonths(months); long days = mdt.until(now, ChronoUnit.DAYS); age += days + \"D \"; mdt = mdt.plusDays(days); long hours = mdt.until(now, ChronoUnit.HOURS); age += hours + \"h \"; mdt = mdt.plusHours(hours); long minutes = mdt.until(now, ChronoUnit.MINUTES); age += minutes + \"m \"; mdt = mdt.plusMinutes(minutes); long seconds = mdt.until(now, ChronoUnit.SECONDS); age += hours + \"s\"; return age;",
|
|
|
+ "params": {
|
|
|
+ "now": 1574005645830
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
----
|
|
|
// TEST[continued]
|