@@ -233,8 +233,8 @@ private static ObjectParser<Builder, Void> createParser(boolean ignoreUnknownFie
233233
234234 private final List <String > indices ;
235235 private final QueryProvider queryProvider ;
236- private final AggProvider aggProvider ;
237236 private final String esqlQuery ;
237+ private final AggProvider aggProvider ;
238238 private final List <SearchSourceBuilder .ScriptField > scriptFields ;
239239 private final Integer scrollSize ;
240240 private final ChunkingConfig chunkingConfig ;
@@ -251,8 +251,8 @@ private DatafeedConfig(
251251 TimeValue frequency ,
252252 List <String > indices ,
253253 QueryProvider queryProvider ,
254- AggProvider aggProvider ,
255254 String esqlQuery ,
255+ AggProvider aggProvider ,
256256 List <SearchSourceBuilder .ScriptField > scriptFields ,
257257 Integer scrollSize ,
258258 ChunkingConfig chunkingConfig ,
@@ -268,8 +268,8 @@ private DatafeedConfig(
268268 this .frequency = frequency ;
269269 this .indices = indices == null ? null : Collections .unmodifiableList (indices );
270270 this .queryProvider = queryProvider == null ? null : new QueryProvider (queryProvider );
271- this .aggProvider = aggProvider == null ? null : new AggProvider (aggProvider );
272271 this .esqlQuery = esqlQuery ;
272+ this .aggProvider = aggProvider == null ? null : new AggProvider (aggProvider );
273273 this .scriptFields = scriptFields == null ? null : Collections .unmodifiableList (scriptFields );
274274 this .scrollSize = scrollSize ;
275275 this .chunkingConfig = chunkingConfig ;
@@ -286,17 +286,15 @@ public DatafeedConfig(StreamInput in) throws IOException {
286286 this .queryDelay = in .readOptionalTimeValue ();
287287 this .frequency = in .readOptionalTimeValue ();
288288 this .indices = in .readOptionalStringCollectionAsList ();
289- // each of these writables are version aware
290- this .queryProvider = in .readOptionalWriteable (QueryProvider ::fromStream );
291- // This reads a boolean from the stream, if true, it sends the stream to the `fromStream` method
292- this .aggProvider = in .readOptionalWriteable (AggProvider ::fromStream );
293- this .esqlQuery = in .readOptionalString ();
294-
295- if (in .readBoolean ()) {
296- this .scriptFields = in .readCollectionAsImmutableList (SearchSourceBuilder .ScriptField ::new );
289+ if (in .getTransportVersion ().onOrAfter (TransportVersions .ESQL_IN_DATAFEEDS )) {
290+ this .queryProvider = in .readOptionalWriteable (QueryProvider ::fromStream );
291+ this .esqlQuery = in .readOptionalString ();
297292 } else {
298- this .scriptFields = null ;
293+ this .queryProvider = QueryProvider .fromStream (in );
294+ this .esqlQuery = null ;
299295 }
296+ this .aggProvider = in .readOptionalWriteable (AggProvider ::fromStream );
297+ this .scriptFields = in .readOptionalCollectionAsList (SearchSourceBuilder .ScriptField ::new );
300298 this .scrollSize = in .readOptionalVInt ();
301299 this .chunkingConfig = in .readOptionalWriteable (ChunkingConfig ::new );
302300 this .headers = in .readImmutableMap (StreamInput ::readString );
@@ -524,9 +522,13 @@ public void writeTo(StreamOutput out) throws IOException {
524522 out .writeOptionalTimeValue (queryDelay );
525523 out .writeOptionalTimeValue (frequency );
526524 out .writeOptionalStringCollection (indices );
527- out .writeOptionalWriteable (queryProvider );
525+ if (out .getTransportVersion ().onOrAfter (TransportVersions .ESQL_IN_DATAFEEDS )) {
526+ out .writeOptionalWriteable (queryProvider );
527+ out .writeOptionalString (esqlQuery );
528+ } else {
529+ queryProvider .writeTo (out );
530+ }
528531 out .writeOptionalWriteable (aggProvider );
529- out .writeOptionalString (esqlQuery );
530532 out .writeOptionalCollection (scriptFields );
531533 out .writeOptionalVInt (scrollSize );
532534 out .writeOptionalWriteable (chunkingConfig );
@@ -778,8 +780,8 @@ public Builder(DatafeedConfig config) {
778780 this .frequency = config .frequency ;
779781 this .indices = new ArrayList <>(config .indices );
780782 this .queryProvider = config .queryProvider == null ? null : new QueryProvider (config .queryProvider );
781- this .aggProvider = config .aggProvider == null ? null : new AggProvider (config .aggProvider );
782783 this .esqlQuery = config .esqlQuery ;
784+ this .aggProvider = config .aggProvider == null ? null : new AggProvider (config .aggProvider );
783785 this .scriptFields = config .scriptFields == null ? null : new ArrayList <>(config .scriptFields );
784786 this .scrollSize = config .scrollSize ;
785787 this .chunkingConfig = config .chunkingConfig ;
@@ -795,22 +797,17 @@ public Builder(StreamInput in) throws IOException {
795797 this .jobId = in .readOptionalString ();
796798 this .queryDelay = in .readOptionalTimeValue ();
797799 this .frequency = in .readOptionalTimeValue ();
798- if (in .readBoolean ()) {
799- this .indices = in .readCollectionAsImmutableList (StreamInput ::readString );
800+ this .indices = in .readOptionalStringCollectionAsList ();
801+ if (in .getTransportVersion ().onOrAfter (TransportVersions .ESQL_IN_DATAFEEDS )) {
802+ this .queryProvider = in .readOptionalWriteable (QueryProvider ::fromStream );
803+ this .esqlQuery = in .readOptionalString ();
800804 } else {
801- this .indices = null ;
805+ this .queryProvider = QueryProvider .fromStream (in );
806+ this .esqlQuery = null ;
802807 }
803- // each of these writables are version aware
804- this .queryProvider = in .readOptionalWriteable (QueryProvider ::fromStream );
805808 // This reads a boolean from the stream, if true, it sends the stream to the `fromStream` method
806809 this .aggProvider = in .readOptionalWriteable (AggProvider ::fromStream );
807- this .esqlQuery = in .readOptionalString ();
808-
809- if (in .readBoolean ()) {
810- this .scriptFields = in .readCollectionAsImmutableList (SearchSourceBuilder .ScriptField ::new );
811- } else {
812- this .scriptFields = null ;
813- }
810+ this .scriptFields = in .readOptionalCollectionAsList (SearchSourceBuilder .ScriptField ::new );
814811 this .scrollSize = in .readOptionalVInt ();
815812 this .chunkingConfig = in .readOptionalWriteable (ChunkingConfig ::new );
816813 this .headers = in .readImmutableMap (StreamInput ::readString );
@@ -828,25 +825,15 @@ public void writeTo(StreamOutput out) throws IOException {
828825 out .writeOptionalString (jobId );
829826 out .writeOptionalTimeValue (queryDelay );
830827 out .writeOptionalTimeValue (frequency );
831- if (indices != null ) {
832- out .writeBoolean (true );
833- out .writeStringCollection (indices );
828+ out .writeOptionalStringCollection (indices );
829+ if (out .getTransportVersion ().onOrAfter (TransportVersions .ESQL_IN_DATAFEEDS )) {
830+ out .writeOptionalWriteable (queryProvider );
831+ out .writeOptionalString (esqlQuery );
834832 } else {
835- out . writeBoolean ( false );
833+ queryProvider . writeTo ( out );
836834 }
837-
838- // Each of these writables are version aware
839- out .writeOptionalWriteable (queryProvider );
840- // This writes a boolean to the stream, if true, it sends the stream to the `writeTo` method
841835 out .writeOptionalWriteable (aggProvider );
842- out .writeOptionalString (esqlQuery );
843-
844- if (scriptFields != null ) {
845- out .writeBoolean (true );
846- out .writeCollection (scriptFields );
847- } else {
848- out .writeBoolean (false );
849- }
836+ out .writeOptionalCollection (scriptFields );
850837 out .writeOptionalVInt (scrollSize );
851838 out .writeOptionalWriteable (chunkingConfig );
852839 out .writeMap (headers , StreamOutput ::writeString );
@@ -1082,8 +1069,8 @@ public DatafeedConfig build() {
10821069 frequency ,
10831070 indices ,
10841071 queryProvider ,
1085- aggProvider ,
10861072 esqlQuery ,
1073+ aggProvider ,
10871074 scriptFields ,
10881075 scrollSize ,
10891076 chunkingConfig ,
0 commit comments