|
@@ -6,6 +6,7 @@
|
|
|
*/
|
|
|
package org.elasticsearch.xpack.core.ml.datafeed;
|
|
|
|
|
|
+import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.action.search.SearchRequest;
|
|
|
import org.elasticsearch.action.support.IndicesOptions;
|
|
|
import org.elasticsearch.common.ParseField;
|
|
@@ -32,6 +33,7 @@ import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
@@ -84,6 +86,7 @@ public class DatafeedUpdate implements Writeable, ToXContentObject {
|
|
|
PARSER.declareObject(Builder::setIndicesOptions,
|
|
|
(p, c) -> IndicesOptions.fromMap(p.map(), SearchRequest.DEFAULT_INDICES_OPTIONS),
|
|
|
DatafeedConfig.INDICES_OPTIONS);
|
|
|
+ PARSER.declareObject(Builder::setRuntimeMappings, (p, c) -> p.map(), SearchSourceBuilder.RUNTIME_MAPPINGS_FIELD);
|
|
|
}
|
|
|
|
|
|
private final String id;
|
|
@@ -99,12 +102,14 @@ public class DatafeedUpdate implements Writeable, ToXContentObject {
|
|
|
private final DelayedDataCheckConfig delayedDataCheckConfig;
|
|
|
private final Integer maxEmptySearches;
|
|
|
private final IndicesOptions indicesOptions;
|
|
|
+ private final Map<String, Object> runtimeMappings;
|
|
|
|
|
|
private DatafeedUpdate(String id, String jobId, TimeValue queryDelay, TimeValue frequency, List<String> indices,
|
|
|
QueryProvider queryProvider, AggProvider aggProvider,
|
|
|
List<SearchSourceBuilder.ScriptField> scriptFields,
|
|
|
Integer scrollSize, ChunkingConfig chunkingConfig, DelayedDataCheckConfig delayedDataCheckConfig,
|
|
|
- Integer maxEmptySearches, IndicesOptions indicesOptions) {
|
|
|
+ Integer maxEmptySearches, IndicesOptions indicesOptions,
|
|
|
+ Map<String, Object> runtimeMappings) {
|
|
|
this.id = id;
|
|
|
this.jobId = jobId;
|
|
|
this.queryDelay = queryDelay;
|
|
@@ -118,6 +123,7 @@ public class DatafeedUpdate implements Writeable, ToXContentObject {
|
|
|
this.delayedDataCheckConfig = delayedDataCheckConfig;
|
|
|
this.maxEmptySearches = maxEmptySearches;
|
|
|
this.indicesOptions = indicesOptions;
|
|
|
+ this.runtimeMappings = runtimeMappings;
|
|
|
}
|
|
|
|
|
|
public DatafeedUpdate(StreamInput in) throws IOException {
|
|
@@ -144,6 +150,11 @@ public class DatafeedUpdate implements Writeable, ToXContentObject {
|
|
|
delayedDataCheckConfig = in.readOptionalWriteable(DelayedDataCheckConfig::new);
|
|
|
maxEmptySearches = in.readOptionalInt();
|
|
|
indicesOptions = in.readBoolean() ? IndicesOptions.readIndicesOptions(in) : null;
|
|
|
+ if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
|
|
|
+ this.runtimeMappings = in.readBoolean() ? in.readMap() : null;
|
|
|
+ } else {
|
|
|
+ this.runtimeMappings = null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -185,6 +196,14 @@ public class DatafeedUpdate implements Writeable, ToXContentObject {
|
|
|
} else {
|
|
|
out.writeBoolean(false);
|
|
|
}
|
|
|
+ if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
|
|
|
+ if (this.runtimeMappings != null) {
|
|
|
+ out.writeBoolean(true);
|
|
|
+ out.writeMap(this.runtimeMappings);
|
|
|
+ } else {
|
|
|
+ out.writeBoolean(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -221,6 +240,7 @@ public class DatafeedUpdate implements Writeable, ToXContentObject {
|
|
|
indicesOptions.toXContent(builder, params);
|
|
|
builder.endObject();
|
|
|
}
|
|
|
+ addOptionalField(builder, SearchSourceBuilder.RUNTIME_MAPPINGS_FIELD, runtimeMappings);
|
|
|
builder.endObject();
|
|
|
return builder;
|
|
|
}
|
|
@@ -251,6 +271,10 @@ public class DatafeedUpdate implements Writeable, ToXContentObject {
|
|
|
return scrollSize;
|
|
|
}
|
|
|
|
|
|
+ public Map<String, Object> getRuntimeMappings() {
|
|
|
+ return runtimeMappings;
|
|
|
+ }
|
|
|
+
|
|
|
Map<String, Object> getQuery() {
|
|
|
return queryProvider == null ? null : queryProvider.getQuery();
|
|
|
}
|
|
@@ -347,6 +371,9 @@ public class DatafeedUpdate implements Writeable, ToXContentObject {
|
|
|
if (indicesOptions != null) {
|
|
|
builder.setIndicesOptions(indicesOptions);
|
|
|
}
|
|
|
+ if (runtimeMappings != null) {
|
|
|
+ builder.setRuntimeMappings(runtimeMappings);
|
|
|
+ }
|
|
|
if (headers.isEmpty() == false) {
|
|
|
builder.setHeaders(filterSecurityHeaders(headers));
|
|
|
}
|
|
@@ -382,13 +409,14 @@ public class DatafeedUpdate implements Writeable, ToXContentObject {
|
|
|
&& Objects.equals(this.scriptFields, that.scriptFields)
|
|
|
&& Objects.equals(this.chunkingConfig, that.chunkingConfig)
|
|
|
&& Objects.equals(this.maxEmptySearches, that.maxEmptySearches)
|
|
|
- && Objects.equals(this.indicesOptions, that.indicesOptions);
|
|
|
+ && Objects.equals(this.indicesOptions, that.indicesOptions)
|
|
|
+ && Objects.equals(this.runtimeMappings, that.runtimeMappings);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int hashCode() {
|
|
|
return Objects.hash(id, jobId, frequency, queryDelay, indices, queryProvider, scrollSize, aggProvider, scriptFields, chunkingConfig,
|
|
|
- delayedDataCheckConfig, maxEmptySearches, indicesOptions);
|
|
|
+ delayedDataCheckConfig, maxEmptySearches, indicesOptions, runtimeMappings);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -408,7 +436,8 @@ public class DatafeedUpdate implements Writeable, ToXContentObject {
|
|
|
&& (chunkingConfig == null || Objects.equals(chunkingConfig, datafeed.getChunkingConfig()))
|
|
|
&& (maxEmptySearches == null || Objects.equals(maxEmptySearches, datafeed.getMaxEmptySearches())
|
|
|
|| (maxEmptySearches == -1 && datafeed.getMaxEmptySearches() == null))
|
|
|
- && (indicesOptions == null || Objects.equals(indicesOptions, datafeed.getIndicesOptions()));
|
|
|
+ && (indicesOptions == null || Objects.equals(indicesOptions, datafeed.getIndicesOptions()))
|
|
|
+ && (runtimeMappings == null || Objects.equals(runtimeMappings, datafeed.getRuntimeMappings()));
|
|
|
}
|
|
|
|
|
|
public static class Builder {
|
|
@@ -426,6 +455,7 @@ public class DatafeedUpdate implements Writeable, ToXContentObject {
|
|
|
private DelayedDataCheckConfig delayedDataCheckConfig;
|
|
|
private Integer maxEmptySearches;
|
|
|
private IndicesOptions indicesOptions;
|
|
|
+ private Map<String, Object> runtimeMappings;
|
|
|
|
|
|
public Builder() {
|
|
|
}
|
|
@@ -448,6 +478,9 @@ public class DatafeedUpdate implements Writeable, ToXContentObject {
|
|
|
this.delayedDataCheckConfig = config.delayedDataCheckConfig;
|
|
|
this.maxEmptySearches = config.maxEmptySearches;
|
|
|
this.indicesOptions = config.indicesOptions;
|
|
|
+ this.runtimeMappings = config.runtimeMappings != null ?
|
|
|
+ new HashMap<>(config.runtimeMappings) :
|
|
|
+ null;
|
|
|
}
|
|
|
|
|
|
public Builder setId(String datafeedId) {
|
|
@@ -530,9 +563,14 @@ public class DatafeedUpdate implements Writeable, ToXContentObject {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ public Builder setRuntimeMappings(Map<String, Object> runtimeMappings) {
|
|
|
+ this.runtimeMappings = runtimeMappings;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
public DatafeedUpdate build() {
|
|
|
return new DatafeedUpdate(id, jobId, queryDelay, frequency, indices, queryProvider, aggProvider, scriptFields, scrollSize,
|
|
|
- chunkingConfig, delayedDataCheckConfig, maxEmptySearches, indicesOptions);
|
|
|
+ chunkingConfig, delayedDataCheckConfig, maxEmptySearches, indicesOptions, runtimeMappings);
|
|
|
}
|
|
|
}
|
|
|
}
|