Skip to content

Commit 05e2209

Browse files
committed
Merge branch 'master' into async_search
2 parents 20aa0fe + a8f413a commit 05e2209

File tree

298 files changed

+6388
-2581
lines changed

Some content is hidden

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

298 files changed

+6388
-2581
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestApiTask.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* @see RestResourcesPlugin
5252
*/
5353
public class CopyRestApiTask extends DefaultTask {
54-
private static final String COPY_TO = "rest-api-spec/api";
54+
private static final String REST_API_PREFIX = "rest-api-spec/api";
5555
final ListProperty<String> includeCore = getProject().getObjects().listProperty(String.class);
5656
final ListProperty<String> includeXpack = getProject().getObjects().listProperty(String.class);
5757

@@ -109,7 +109,7 @@ public FileTree getInputDir() {
109109

110110
@OutputDirectory
111111
public File getOutputDir() {
112-
return new File(getTestSourceSet().getOutput().getResourcesDir(), COPY_TO);
112+
return new File(getTestSourceSet().getOutput().getResourcesDir(), REST_API_PREFIX);
113113
}
114114

115115
@TaskAction
@@ -132,7 +132,13 @@ void copy() {
132132
project.copy(c -> {
133133
c.from(project.zipTree(coreConfig.getSingleFile()));
134134
c.into(getTestSourceSet().getOutput().getResourcesDir()); // this ends up as the same dir as outputDir
135-
c.include(includeCore.get().stream().map(prefix -> COPY_TO + "/" + prefix + "*/**").collect(Collectors.toList()));
135+
if (includeCore.get().isEmpty()) {
136+
c.include(REST_API_PREFIX + "/**");
137+
} else {
138+
c.include(
139+
includeCore.get().stream().map(prefix -> REST_API_PREFIX + "/" + prefix + "*/**").collect(Collectors.toList())
140+
);
141+
}
136142
});
137143
}
138144
// only copy x-pack specs if explicitly instructed

buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestTestsTask.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* @see RestResourcesPlugin
4949
*/
5050
public class CopyRestTestsTask extends DefaultTask {
51-
private static final String COPY_TO = "rest-api-spec/test";
51+
private static final String REST_TEST_PREFIX = "rest-api-spec/test";
5252
final ListProperty<String> includeCore = getProject().getObjects().listProperty(String.class);
5353
final ListProperty<String> includeXpack = getProject().getObjects().listProperty(String.class);
5454

@@ -103,7 +103,7 @@ public FileTree getInputDir() {
103103

104104
@OutputDirectory
105105
public File getOutputDir() {
106-
return new File(getTestSourceSet().getOutput().getResourcesDir(), COPY_TO);
106+
return new File(getTestSourceSet().getOutput().getResourcesDir(), REST_TEST_PREFIX);
107107
}
108108

109109
@TaskAction
@@ -128,7 +128,9 @@ void copy() {
128128
project.copy(c -> {
129129
c.from(project.zipTree(coreConfig.getSingleFile()));
130130
c.into(getTestSourceSet().getOutput().getResourcesDir()); // this ends up as the same dir as outputDir
131-
c.include(includeCore.get().stream().map(prefix -> COPY_TO + "/" + prefix + "*/**").collect(Collectors.toList()));
131+
c.include(
132+
includeCore.get().stream().map(prefix -> REST_TEST_PREFIX + "/" + prefix + "*/**").collect(Collectors.toList())
133+
);
132134
});
133135
}
134136
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.2.1
1+
6.2.2

buildSrc/version.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
elasticsearch = 8.0.0
2-
lucene = 8.5.0-snapshot-fa75139efea
2+
lucene = 8.5.0-snapshot-c4475920b08
33

44
bundled_jdk_vendor = adoptopenjdk
55
bundled_jdk = 13.0.2+8

client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java

+4
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,10 @@ Params withRouting(String routing) {
913913
}
914914

915915
Params withSlices(int slices) {
916+
if (slices == 0) {
917+
// translate to "auto" value in rest request so the receiving end doesn't throw error
918+
return putParam("slices", AbstractBulkByScrollRequest.AUTO_SLICES_VALUE);
919+
}
916920
return putParam("slices", String.valueOf(slices));
917921
}
918922

client/rest-high-level/src/main/java/org/elasticsearch/client/analytics/TopMetricsAggregationBuilder.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.elasticsearch.search.sort.SortBuilder;
3333

3434
import java.io.IOException;
35+
import java.util.Arrays;
36+
import java.util.List;
3537
import java.util.Map;
3638

3739
/**
@@ -49,20 +51,20 @@ public class TopMetricsAggregationBuilder extends AbstractAggregationBuilder<Top
4951

5052
private final SortBuilder<?> sort;
5153
private final int size;
52-
private final String metric;
54+
private final List<String> metrics;
5355

5456
/**
5557
* Build the request.
5658
* @param name the name of the metric
5759
* @param sort the sort key used to select the top metrics
5860
* @param size number of results to return per bucket
59-
* @param metric the name of the field to select
61+
* @param metrics the names of the fields to select
6062
*/
61-
public TopMetricsAggregationBuilder(String name, SortBuilder<?> sort, int size, String metric) {
63+
public TopMetricsAggregationBuilder(String name, SortBuilder<?> sort, int size, String... metrics) {
6264
super(name);
6365
this.sort = sort;
6466
this.size = size;
65-
this.metric = metric;
67+
this.metrics = Arrays.asList(metrics);
6668
}
6769

6870
@Override
@@ -78,7 +80,11 @@ protected XContentBuilder internalXContent(XContentBuilder builder, Params param
7880
sort.toXContent(builder, params);
7981
builder.endArray();
8082
builder.field("size", size);
81-
builder.startObject("metric").field("field", metric).endObject();
83+
builder.startArray("metrics");
84+
for (String metric: metrics) {
85+
builder.startObject().field("field", metric).endObject();
86+
}
87+
builder.endArray();
8288
}
8389
return builder.endObject();
8490
}

client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/DateHistogramGroupSource.java

+77-52
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
package org.elasticsearch.client.transform.transforms.pivot;
2121

2222
import org.elasticsearch.common.ParseField;
23+
import org.elasticsearch.common.Strings;
2324
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
2425
import org.elasticsearch.common.xcontent.ObjectParser;
2526
import org.elasticsearch.common.xcontent.ToXContentFragment;
2627
import org.elasticsearch.common.xcontent.ToXContentObject;
2728
import org.elasticsearch.common.xcontent.XContentBuilder;
2829
import org.elasticsearch.common.xcontent.XContentParser;
30+
import org.elasticsearch.script.Script;
2931
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
3032

3133
import java.io.IOException;
@@ -48,23 +50,28 @@ public class DateHistogramGroupSource extends SingleGroupSource implements ToXCo
4850

4951
// From DateHistogramAggregationBuilder in core, transplanted and modified to a set
5052
// so we don't need to import a dependency on the class
51-
private static final Set<String> DATE_FIELD_UNITS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
52-
"year",
53-
"1y",
54-
"quarter",
55-
"1q",
56-
"month",
57-
"1M",
58-
"week",
59-
"1w",
60-
"day",
61-
"1d",
62-
"hour",
63-
"1h",
64-
"minute",
65-
"1m",
66-
"second",
67-
"1s")));
53+
private static final Set<String> DATE_FIELD_UNITS = Collections.unmodifiableSet(
54+
new HashSet<>(
55+
Arrays.asList(
56+
"year",
57+
"1y",
58+
"quarter",
59+
"1q",
60+
"month",
61+
"1M",
62+
"week",
63+
"1w",
64+
"day",
65+
"1d",
66+
"hour",
67+
"1h",
68+
"minute",
69+
"1m",
70+
"second",
71+
"1s"
72+
)
73+
)
74+
);
6875

6976
/**
7077
* Interval can be specified in 2 ways:
@@ -76,6 +83,7 @@ public class DateHistogramGroupSource extends SingleGroupSource implements ToXCo
7683
*/
7784
public interface Interval extends ToXContentFragment {
7885
String getName();
86+
7987
DateHistogramInterval getInterval();
8088
}
8189

@@ -131,8 +139,9 @@ public static class CalendarInterval implements Interval {
131139
public CalendarInterval(DateHistogramInterval interval) {
132140
this.interval = interval;
133141
if (DATE_FIELD_UNITS.contains(interval.toString()) == false) {
134-
throw new IllegalArgumentException("The supplied interval [" + interval + "] could not be parsed " +
135-
"as a calendar interval.");
142+
throw new IllegalArgumentException(
143+
"The supplied interval [" + interval + "] could not be parsed " + "as a calendar interval."
144+
);
136145
}
137146
}
138147

@@ -173,33 +182,35 @@ public int hashCode() {
173182
}
174183
}
175184

176-
private static final ConstructingObjectParser<DateHistogramGroupSource, Void> PARSER =
177-
new ConstructingObjectParser<>("date_histogram_group_source",
178-
true,
179-
(args) -> {
180-
String field = (String)args[0];
181-
String fixedInterval = (String) args[1];
182-
String calendarInterval = (String) args[2];
183-
184-
Interval interval = null;
185-
186-
if (fixedInterval != null && calendarInterval != null) {
187-
throw new IllegalArgumentException("You must specify either fixed_interval or calendar_interval, found both");
188-
} else if (fixedInterval != null) {
189-
interval = new FixedInterval(new DateHistogramInterval(fixedInterval));
190-
} else if (calendarInterval != null) {
191-
interval = new CalendarInterval(new DateHistogramInterval(calendarInterval));
192-
} else {
193-
throw new IllegalArgumentException("You must specify either fixed_interval or calendar_interval, found none");
194-
}
195-
196-
ZoneId zoneId = (ZoneId) args[3];
197-
return new DateHistogramGroupSource(field, interval, zoneId);
198-
});
185+
private static final ConstructingObjectParser<DateHistogramGroupSource, Void> PARSER = new ConstructingObjectParser<>(
186+
"date_histogram_group_source",
187+
true,
188+
(args) -> {
189+
String field = (String) args[0];
190+
Script script = (Script) args[1];
191+
String fixedInterval = (String) args[2];
192+
String calendarInterval = (String) args[3];
193+
ZoneId zoneId = (ZoneId) args[4];
194+
195+
Interval interval = null;
196+
197+
if (fixedInterval != null && calendarInterval != null) {
198+
throw new IllegalArgumentException("You must specify either fixed_interval or calendar_interval, found both");
199+
} else if (fixedInterval != null) {
200+
interval = new FixedInterval(new DateHistogramInterval(fixedInterval));
201+
} else if (calendarInterval != null) {
202+
interval = new CalendarInterval(new DateHistogramInterval(calendarInterval));
203+
} else {
204+
throw new IllegalArgumentException("You must specify either fixed_interval or calendar_interval, found none");
205+
}
206+
207+
return new DateHistogramGroupSource(field, script, interval, zoneId);
208+
}
209+
);
199210

200211
static {
201212
PARSER.declareString(optionalConstructorArg(), FIELD);
202-
213+
Script.declareScript(PARSER, optionalConstructorArg(), SCRIPT);
203214
PARSER.declareString(optionalConstructorArg(), new ParseField(FixedInterval.NAME));
204215
PARSER.declareString(optionalConstructorArg(), new ParseField(CalendarInterval.NAME));
205216

@@ -219,8 +230,8 @@ public static DateHistogramGroupSource fromXContent(final XContentParser parser)
219230
private final Interval interval;
220231
private final ZoneId timeZone;
221232

222-
DateHistogramGroupSource(String field, Interval interval, ZoneId timeZone) {
223-
super(field);
233+
DateHistogramGroupSource(String field, Script script, Interval interval, ZoneId timeZone) {
234+
super(field, script);
224235
this.interval = interval;
225236
this.timeZone = timeZone;
226237
}
@@ -241,9 +252,7 @@ public ZoneId getTimeZone() {
241252
@Override
242253
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
243254
builder.startObject();
244-
if (field != null) {
245-
builder.field(FIELD.getPreferredName(), field);
246-
}
255+
super.innerXContent(builder, params);
247256
interval.toXContent(builder, params);
248257
if (timeZone != null) {
249258
builder.field(TIME_ZONE.getPreferredName(), timeZone.toString());
@@ -264,23 +273,29 @@ public boolean equals(Object other) {
264273

265274
final DateHistogramGroupSource that = (DateHistogramGroupSource) other;
266275

267-
return Objects.equals(this.field, that.field) &&
268-
Objects.equals(this.interval, that.interval) &&
269-
Objects.equals(this.timeZone, that.timeZone);
276+
return Objects.equals(this.field, that.field)
277+
&& Objects.equals(this.interval, that.interval)
278+
&& Objects.equals(this.timeZone, that.timeZone);
270279
}
271280

272281
@Override
273282
public int hashCode() {
274283
return Objects.hash(field, interval, timeZone);
275284
}
276285

286+
@Override
287+
public String toString() {
288+
return Strings.toString(this, true, true);
289+
}
290+
277291
public static Builder builder() {
278292
return new Builder();
279293
}
280294

281295
public static class Builder {
282296

283297
private String field;
298+
private Script script;
284299
private Interval interval;
285300
private ZoneId timeZone;
286301

@@ -294,6 +309,16 @@ public Builder setField(String field) {
294309
return this;
295310
}
296311

312+
/**
313+
* The script with which to construct the date histogram grouping
314+
* @param script The script
315+
* @return The {@link Builder} with the script set.
316+
*/
317+
public Builder setScript(Script script) {
318+
this.script = script;
319+
return this;
320+
}
321+
297322
/**
298323
* Set the interval for the DateHistogram grouping
299324
* @param interval a fixed or calendar interval
@@ -315,7 +340,7 @@ public Builder setTimeZone(ZoneId timeZone) {
315340
}
316341

317342
public DateHistogramGroupSource build() {
318-
return new DateHistogramGroupSource(field, interval, timeZone);
343+
return new DateHistogramGroupSource(field, script, interval, timeZone);
319344
}
320345
}
321346
}

0 commit comments

Comments
 (0)