Skip to content

Commit a38dd9e

Browse files
EQL: Fix EqlSearchRequest serialization (bwc) (#91402) (#91406)
1 parent 175d6bd commit a38dd9e

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

docs/changelog/91402.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 91402
2+
summary: Fix EQLSearchRequest serialization (bwc)
3+
area: EQL
4+
type: bug
5+
issues: []

x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/action/EqlSearchRequest.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,10 @@ public EqlSearchRequest(StreamInput in) throws IOException {
115115
if (in.getVersion().onOrAfter(Version.V_7_15_0)) {
116116
this.ccsMinimizeRoundtrips = in.readBoolean();
117117
}
118-
if (in.getVersion().onOrAfter(Version.V_8_0_0)) { // TODO: Remove after backport
119-
this.waitForCompletionTimeout = in.readOptionalTimeValue();
120-
this.keepAlive = in.readOptionalTimeValue();
121-
this.keepOnCompletion = in.readBoolean();
122-
}
123-
if (in.getVersion().onOrAfter(Version.V_7_10_0)) {
118+
this.waitForCompletionTimeout = in.readOptionalTimeValue();
119+
this.keepAlive = in.readOptionalTimeValue();
120+
this.keepOnCompletion = in.readBoolean();
121+
if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
124122
resultPosition = in.readString();
125123
}
126124
if (in.getVersion().onOrAfter(Version.V_7_13_0)) {
@@ -223,10 +221,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
223221
builder.field(KEY_FETCH_SIZE, fetchSize());
224222
builder.field(KEY_QUERY, query);
225223
if (waitForCompletionTimeout != null) {
226-
builder.field(KEY_WAIT_FOR_COMPLETION_TIMEOUT, waitForCompletionTimeout);
224+
builder.field(KEY_WAIT_FOR_COMPLETION_TIMEOUT, waitForCompletionTimeout.getStringRep());
227225
}
228226
if (keepAlive != null) {
229-
builder.field(KEY_KEEP_ALIVE, keepAlive);
227+
builder.field(KEY_KEEP_ALIVE, keepAlive.getStringRep());
230228
}
231229
builder.field(KEY_KEEP_ON_COMPLETION, keepOnCompletion);
232230
builder.field(KEY_RESULT_POSITION, resultPosition);
@@ -435,13 +433,10 @@ public void writeTo(StreamOutput out) throws IOException {
435433
if (out.getVersion().onOrAfter(Version.V_7_15_0)) {
436434
out.writeBoolean(ccsMinimizeRoundtrips);
437435
}
438-
if (out.getVersion().onOrAfter(Version.V_8_0_0)) { // TODO: Remove after backport
439-
out.writeOptionalTimeValue(waitForCompletionTimeout);
440-
out.writeOptionalTimeValue(keepAlive);
441-
out.writeBoolean(keepOnCompletion);
442-
}
443-
444-
if (out.getVersion().onOrAfter(Version.V_7_10_0)) {
436+
out.writeOptionalTimeValue(waitForCompletionTimeout);
437+
out.writeOptionalTimeValue(keepAlive);
438+
out.writeBoolean(keepOnCompletion);
439+
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
445440
out.writeString(resultPosition);
446441
}
447442
if (out.getVersion().onOrAfter(Version.V_7_13_0)) {

x-pack/plugin/eql/src/test/java/org/elasticsearch/xpack/eql/action/EqlSearchRequestTests.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1111
import org.elasticsearch.common.io.stream.Writeable;
1212
import org.elasticsearch.common.settings.Settings;
13+
import org.elasticsearch.core.TimeValue;
1314
import org.elasticsearch.index.query.QueryBuilder;
1415
import org.elasticsearch.search.SearchModule;
1516
import org.elasticsearch.search.fetch.subphase.FieldAndFormat;
@@ -76,14 +77,22 @@ protected EqlSearchRequest createTestInstance() {
7677
.size(randomInt(50))
7778
.query(randomAlphaOfLength(10))
7879
.ccsMinimizeRoundtrips(ccsMinimizeRoundtrips)
80+
.waitForCompletionTimeout(randomTV())
81+
.keepAlive(randomTV())
82+
.keepOnCompletion(randomBoolean())
7983
.fetchFields(randomFetchFields)
80-
.runtimeMappings(randomRuntimeMappings());
84+
.runtimeMappings(randomRuntimeMappings())
85+
.resultPosition(randomFrom("tail", "head"));
8186
} catch (IOException ex) {
8287
assertNotNull("unexpected IOException " + ex.getCause().getMessage(), ex);
8388
}
8489
return null;
8590
}
8691

92+
private TimeValue randomTV() {
93+
return TimeValue.parseTimeValue(randomTimeValue(), null, "test");
94+
}
95+
8796
protected QueryBuilder parseFilter(String filter) throws IOException {
8897
XContentParser parser = createParser(JsonXContent.jsonXContent, filter);
8998
return parseFilter(parser);
@@ -123,6 +132,7 @@ protected EqlSearchRequest mutateInstanceForVersion(EqlSearchRequest instance, V
123132
mutatedInstance.keepOnCompletion(instance.keepOnCompletion());
124133
mutatedInstance.fetchFields(version.onOrAfter(Version.V_7_13_0) ? instance.fetchFields() : null);
125134
mutatedInstance.runtimeMappings(version.onOrAfter(Version.V_7_13_0) ? instance.runtimeMappings() : emptyMap());
135+
mutatedInstance.resultPosition(version.onOrAfter(Version.V_8_0_0) ? instance.resultPosition() : "tail");
126136

127137
return mutatedInstance;
128138
}

0 commit comments

Comments
 (0)