Skip to content

Commit 337a51c

Browse files
committed
Merge remote-tracking branch 'origin/master' into slm-retention
2 parents 67ff2ef + 796dec3 commit 337a51c

File tree

88 files changed

+2483
-624
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2483
-624
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/ml/datafeed/DatafeedUpdate.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.elasticsearch.client.ml.datafeed;
2020

21-
import org.elasticsearch.client.ml.job.config.Job;
2221
import org.elasticsearch.common.ParseField;
2322
import org.elasticsearch.common.bytes.BytesArray;
2423
import org.elasticsearch.common.bytes.BytesReference;
@@ -57,7 +56,6 @@ public class DatafeedUpdate implements ToXContentObject {
5756
static {
5857
PARSER.declareString(ConstructingObjectParser.constructorArg(), DatafeedConfig.ID);
5958

60-
PARSER.declareString(Builder::setJobId, Job.ID);
6159
PARSER.declareStringArray(Builder::setIndices, DatafeedConfig.INDEXES);
6260
PARSER.declareStringArray(Builder::setIndices, DatafeedConfig.INDICES);
6361
PARSER.declareString((builder, val) -> builder.setQueryDelay(
@@ -88,7 +86,6 @@ private static BytesReference parseBytes(XContentParser parser) throws IOExcepti
8886
}
8987

9088
private final String id;
91-
private final String jobId;
9289
private final TimeValue queryDelay;
9390
private final TimeValue frequency;
9491
private final List<String> indices;
@@ -99,11 +96,10 @@ private static BytesReference parseBytes(XContentParser parser) throws IOExcepti
9996
private final ChunkingConfig chunkingConfig;
10097
private final DelayedDataCheckConfig delayedDataCheckConfig;
10198

102-
private DatafeedUpdate(String id, String jobId, TimeValue queryDelay, TimeValue frequency, List<String> indices, BytesReference query,
99+
private DatafeedUpdate(String id, TimeValue queryDelay, TimeValue frequency, List<String> indices, BytesReference query,
103100
BytesReference aggregations, List<SearchSourceBuilder.ScriptField> scriptFields, Integer scrollSize,
104101
ChunkingConfig chunkingConfig, DelayedDataCheckConfig delayedDataCheckConfig) {
105102
this.id = id;
106-
this.jobId = jobId;
107103
this.queryDelay = queryDelay;
108104
this.frequency = frequency;
109105
this.indices = indices;
@@ -126,7 +122,6 @@ public String getId() {
126122
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
127123
builder.startObject();
128124
builder.field(DatafeedConfig.ID.getPreferredName(), id);
129-
addOptionalField(builder, Job.ID, jobId);
130125
if (queryDelay != null) {
131126
builder.field(DatafeedConfig.QUERY_DELAY.getPreferredName(), queryDelay.getStringRep());
132127
}
@@ -162,10 +157,6 @@ private void addOptionalField(XContentBuilder builder, ParseField field, Object
162157
}
163158
}
164159

165-
public String getJobId() {
166-
return jobId;
167-
}
168-
169160
public TimeValue getQueryDelay() {
170161
return queryDelay;
171162
}
@@ -228,7 +219,6 @@ public boolean equals(Object other) {
228219
DatafeedUpdate that = (DatafeedUpdate) other;
229220

230221
return Objects.equals(this.id, that.id)
231-
&& Objects.equals(this.jobId, that.jobId)
232222
&& Objects.equals(this.frequency, that.frequency)
233223
&& Objects.equals(this.queryDelay, that.queryDelay)
234224
&& Objects.equals(this.indices, that.indices)
@@ -247,7 +237,7 @@ public boolean equals(Object other) {
247237
*/
248238
@Override
249239
public int hashCode() {
250-
return Objects.hash(id, jobId, frequency, queryDelay, indices, asMap(query), scrollSize, asMap(aggregations), scriptFields,
240+
return Objects.hash(id, frequency, queryDelay, indices, asMap(query), scrollSize, asMap(aggregations), scriptFields,
251241
chunkingConfig, delayedDataCheckConfig);
252242
}
253243

@@ -258,7 +248,6 @@ public static Builder builder(String id) {
258248
public static class Builder {
259249

260250
private String id;
261-
private String jobId;
262251
private TimeValue queryDelay;
263252
private TimeValue frequency;
264253
private List<String> indices;
@@ -275,7 +264,6 @@ public Builder(String id) {
275264

276265
public Builder(DatafeedUpdate config) {
277266
this.id = config.id;
278-
this.jobId = config.jobId;
279267
this.queryDelay = config.queryDelay;
280268
this.frequency = config.frequency;
281269
this.indices = config.indices;
@@ -287,11 +275,6 @@ public Builder(DatafeedUpdate config) {
287275
this.delayedDataCheckConfig = config.delayedDataCheckConfig;
288276
}
289277

290-
public Builder setJobId(String jobId) {
291-
this.jobId = jobId;
292-
return this;
293-
}
294-
295278
public Builder setIndices(List<String> indices) {
296279
this.indices = indices;
297280
return this;
@@ -364,7 +347,7 @@ public Builder setDelayedDataCheckConfig(DelayedDataCheckConfig delayedDataCheck
364347
}
365348

366349
public DatafeedUpdate build() {
367-
return new DatafeedUpdate(id, jobId, queryDelay, frequency, indices, query, aggregations, scriptFields, scrollSize,
350+
return new DatafeedUpdate(id, queryDelay, frequency, indices, query, aggregations, scriptFields, scrollSize,
368351
chunkingConfig, delayedDataCheckConfig);
369352
}
370353

client/rest-high-level/src/test/java/org/elasticsearch/client/MachineLearningIT.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -463,31 +463,6 @@ public void testUpdateDatafeed() throws Exception {
463463
assertThat(datafeedUpdate.getScrollSize(), equalTo(updatedDatafeed.getScrollSize()));
464464
}
465465

466-
public void testUpdateDatafeed_UpdatingJobIdIsDeprecated() throws Exception {
467-
MachineLearningClient machineLearningClient = highLevelClient().machineLearning();
468-
469-
String jobId = randomValidJobId();
470-
Job job = buildJob(jobId);
471-
execute(new PutJobRequest(job), machineLearningClient::putJob, machineLearningClient::putJobAsync);
472-
473-
String anotherJobId = randomValidJobId();
474-
Job anotherJob = buildJob(anotherJobId);
475-
execute(new PutJobRequest(anotherJob), machineLearningClient::putJob, machineLearningClient::putJobAsync);
476-
477-
String datafeedId = "datafeed-" + jobId;
478-
DatafeedConfig datafeedConfig = DatafeedConfig.builder(datafeedId, jobId).setIndices("some_data_index").build();
479-
execute(new PutDatafeedRequest(datafeedConfig), machineLearningClient::putDatafeed, machineLearningClient::putDatafeedAsync);
480-
481-
DatafeedUpdate datafeedUpdateWithChangedJobId = DatafeedUpdate.builder(datafeedId).setJobId(anotherJobId).build();
482-
WarningFailureException exception = expectThrows(
483-
WarningFailureException.class,
484-
() -> execute(
485-
new UpdateDatafeedRequest(datafeedUpdateWithChangedJobId),
486-
machineLearningClient::updateDatafeed,
487-
machineLearningClient::updateDatafeedAsync));
488-
assertThat(exception.getResponse().getWarnings(), contains("The ability to update a datafeed's job_id is deprecated."));
489-
}
490-
491466
public void testGetDatafeed() throws Exception {
492467
String jobId1 = "test-get-datafeed-job-1";
493468
String jobId2 = "test-get-datafeed-job-2";

client/rest-high-level/src/test/java/org/elasticsearch/client/ml/datafeed/DatafeedUpdateTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ public class DatafeedUpdateTests extends AbstractXContentTestCase<DatafeedUpdate
3434

3535
public static DatafeedUpdate createRandom() {
3636
DatafeedUpdate.Builder builder = new DatafeedUpdate.Builder(DatafeedConfigTests.randomValidDatafeedId());
37-
if (randomBoolean()) {
38-
builder.setJobId(randomAlphaOfLength(10));
39-
}
4037
if (randomBoolean()) {
4138
builder.setQueryDelay(TimeValue.timeValueMillis(randomIntBetween(1, Integer.MAX_VALUE)));
4239
}

docs/painless/painless-guide/painless-datetime.asciidoc

Lines changed: 190 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ document is most commonly accessible through an input called `doc`.
541541
+
542542
[source,Painless]
543543
----
544-
def input = doc['input_datetime'].value;
544+
ZonedDateTime input = doc['input_datetime'].value;
545545
String output = input.format(DateTimeFormatter.ISO_INSTANT); <1>
546546
----
547547
<1> Note the use of a built-in DateTimeFormatter.
@@ -584,8 +584,8 @@ if (doc.containsKey('start') && doc.containsKey('end')) { <1>
584584
585585
if (doc['start'].size() > 0 && doc['end'].size() > 0) { <2>
586586
587-
def start = doc['start'].value;
588-
def end = doc['end'].value;
587+
ZonedDateTime start = doc['start'].value;
588+
ZonedDateTime end = doc['end'].value;
589589
long differenceInMillis = ChronoUnit.MILLIS.between(start, end);
590590
591591
// handle difference in times
@@ -660,7 +660,7 @@ preferred as there is no need to parse it for comparision.
660660
[source,Painless]
661661
----
662662
long now = params['now'];
663-
def inputDateTime = doc['input_datetime'];
663+
ZonedDateTime inputDateTime = doc['input_datetime'];
664664
long millisDateTime = zdt.toInstant().toEpochMilli();
665665
long elapsedTime = now - millisDateTime;
666666
----
@@ -712,9 +712,194 @@ long elapsedTime = now - millisDateTime;
712712
String nowString = params['now'];
713713
ZonedDateTime nowZdt = ZonedDateTime.parse(datetime); <1>
714714
long now = ZonedDateTime.toInstant().toEpochMilli();
715-
def inputDateTime = doc['input_datetime'];
715+
ZonedDateTime inputDateTime = doc['input_datetime'];
716716
long millisDateTime = zdt.toInstant().toEpochMilli();
717717
long elapsedTime = now - millisDateTime;
718718
----
719719
<1> Note this parses the same string datetime every time the script runs. Use a
720720
numeric datetime to avoid a significant performance hit.
721+
722+
==== Datetime Examples in Contexts
723+
724+
===== Load the Example Data
725+
726+
Run the following curl commands to load the data necessary for the context
727+
examples into an Elasticsearch cluster:
728+
729+
. Create {ref}/mapping.html[mappings] for the sample data.
730+
+
731+
[source,js]
732+
----
733+
PUT /messages
734+
{
735+
"mappings": {
736+
"properties": {
737+
"priority": {
738+
"type": "integer"
739+
},
740+
"datetime": {
741+
"type": "date"
742+
},
743+
"message": {
744+
"type": "text"
745+
}
746+
}
747+
}
748+
}
749+
----
750+
+
751+
// CONSOLE
752+
+
753+
. Load the sample data.
754+
+
755+
[source,js]
756+
----
757+
POST /_bulk
758+
{ "index" : { "_index" : "messages", "_id" : "1" } }
759+
{ "priority": 1, "datetime": "2019-07-17T12:13:14Z", "message": "m1" }
760+
{ "index" : { "_index" : "messages", "_id" : "2" } }
761+
{ "priority": 1, "datetime": "2019-07-24T01:14:59Z", "message": "m2" }
762+
{ "index" : { "_index" : "messages", "_id" : "3" } }
763+
{ "priority": 2, "datetime": "1983-10-14T00:36:42Z", "message": "m3" }
764+
{ "index" : { "_index" : "messages", "_id" : "4" } }
765+
{ "priority": 3, "datetime": "1983-10-10T02:15:15Z", "message": "m4" }
766+
{ "index" : { "_index" : "messages", "_id" : "5" } }
767+
{ "priority": 3, "datetime": "1983-10-10T17:18:19Z", "message": "m5" }
768+
{ "index" : { "_index" : "messages", "_id" : "6" } }
769+
{ "priority": 1, "datetime": "2019-08-03T17:19:31Z", "message": "m6" }
770+
{ "index" : { "_index" : "messages", "_id" : "7" } }
771+
{ "priority": 3, "datetime": "2019-08-04T17:20:00Z", "message": "m7" }
772+
{ "index" : { "_index" : "messages", "_id" : "8" } }
773+
{ "priority": 2, "datetime": "2019-08-04T18:01:01Z", "message": "m8" }
774+
{ "index" : { "_index" : "messages", "_id" : "9" } }
775+
{ "priority": 3, "datetime": "1983-10-10T19:00:45Z", "message": "m9" }
776+
{ "index" : { "_index" : "messages", "_id" : "10" } }
777+
{ "priority": 2, "datetime": "2019-07-23T23:39:54Z", "message": "m10" }
778+
----
779+
+
780+
// CONSOLE
781+
// TEST[continued]
782+
783+
===== Day-of-the-Week Bucket Aggregation Example
784+
785+
The following example uses a
786+
{ref}/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-script[terms aggregation]
787+
as part of the
788+
<<painless-bucket-script-agg-context, bucket script aggregation context>> to
789+
display the number of messages from each day-of-the-week.
790+
791+
[source,js]
792+
----
793+
GET /messages/_search?pretty=true
794+
{
795+
"aggs": {
796+
"day-of-week-count": {
797+
"terms": {
798+
"script": "return doc[\"datetime\"].value.getDayOfWeekEnum();"
799+
}
800+
}
801+
}
802+
}
803+
----
804+
// CONSOLE
805+
// TEST[continued]
806+
807+
===== Morning/Evening Bucket Aggregation Example
808+
809+
The following example uses a
810+
{ref}/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-script[terms aggregation]
811+
as part of the
812+
<<painless-bucket-script-agg-context, bucket script aggregation context>> to
813+
display the number of messages received in the morning versus the evening.
814+
815+
[source,js]
816+
----
817+
GET /messages/_search?pretty=true
818+
{
819+
"aggs": {
820+
"am-pm-count": {
821+
"terms": {
822+
"script": "return doc[\"datetime\"].value.getHour() < 12 ? \"AM\" : \"PM\";"
823+
}
824+
}
825+
}
826+
}
827+
----
828+
// CONSOLE
829+
// TEST[continued]
830+
831+
===== Age of a Message Script Field Example
832+
833+
The following example uses a
834+
{ref}/search-request-script-fields.html[script field] as part of the
835+
<<painless-field-context, field context>> to display the elapsed time between
836+
"now" and when a message was received.
837+
838+
[source,js]
839+
----
840+
GET /_search?pretty=true
841+
{
842+
"query" : {
843+
"match_all": {}
844+
},
845+
"script_fields" : {
846+
"message_age" : {
847+
"script" : {
848+
"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;",
849+
"params": {
850+
"now": 1574005645830
851+
}
852+
}
853+
}
854+
}
855+
}
856+
----
857+
// CONSOLE
858+
// TEST[continued]
859+
860+
The following shows the script broken into multiple lines:
861+
862+
[source,Painless]
863+
----
864+
ZonedDateTime now = ZonedDateTime.ofInstant(
865+
Instant.ofEpochMilli(params['now']), ZoneId.of('Z')); <1>
866+
ZonedDateTime mdt = doc['datetime'].value; <2>
867+
868+
String age;
869+
870+
long years = mdt.until(now, ChronoUnit.YEARS); <3>
871+
age = years + 'Y '; <4>
872+
mdt = mdt.plusYears(years); <5>
873+
874+
long months = mdt.until(now, ChronoUnit.MONTHS);
875+
age += months + 'M ';
876+
mdt = mdt.plusMonths(months);
877+
878+
long days = mdt.until(now, ChronoUnit.DAYS);
879+
age += days + 'D ';
880+
mdt = mdt.plusDays(days);
881+
882+
long hours = mdt.until(now, ChronoUnit.HOURS);
883+
age += hours + 'h ';
884+
mdt = mdt.plusHours(hours);
885+
886+
long minutes = mdt.until(now, ChronoUnit.MINUTES);
887+
age += minutes + 'm ';
888+
mdt = mdt.plusMinutes(minutes);
889+
890+
long seconds = mdt.until(now, ChronoUnit.SECONDS);
891+
age += hours + 's';
892+
893+
return age; <6>
894+
----
895+
<1> Parse the datetime "now" as input from the user-defined params.
896+
<2> Store the datetime the message was received as a `ZonedDateTime`.
897+
<3> Find the difference in years between "now" and the datetime the message was
898+
received.
899+
<4> Add the difference in years later returned in the format
900+
`Y <years> ...` for the age of a message.
901+
<5> Add the years so only the remainder of the months, days, etc. remain as the
902+
difference between "now" and the datetime the message was received. Repeat this
903+
pattern until the desired granularity is reached (seconds in this example).
904+
<6> Return the age of the message in the format
905+
`Y <years> M <months> D <days> h <hours> m <minutes> s <seconds>`.

docs/reference/mapping/types.asciidoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ string:: <<text,`text`>> and <<keyword,`keyword`>>
5454

5555
<<flattened>>:: Allows an entire JSON object to be indexed as a single field.
5656

57+
<<shape>>:: `shape` for arbitrary cartesian geometries.
58+
5759
[float]
5860
[[types-array-handling]]
5961
=== Arrays
@@ -121,4 +123,6 @@ include::types/sparse-vector.asciidoc[]
121123

122124
include::types/text.asciidoc[]
123125

124-
include::types/token-count.asciidoc[]
126+
include::types/token-count.asciidoc[]
127+
128+
include::types/shape.asciidoc[]

0 commit comments

Comments
 (0)