Skip to content

Commit

Permalink
Fix backward compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Maurya <[email protected]>
  • Loading branch information
rishabhmaurya committed Apr 5, 2024
1 parent f71c5d1 commit f40465a
Showing 1 changed file with 44 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,6 @@ public SearchSourceBuilder(StreamInput in) throws IOException {
if (in.readBoolean()) {
scriptFields = in.readList(ScriptField::new);
}
if (in.readBoolean()) {
derivedFieldsObject = in.readMap();
}
if (in.readBoolean()) {
derivedFields = in.readList(DerivedField::new);
}
size = in.readVInt();
if (in.readBoolean()) {
int size = in.readVInt();
Expand Down Expand Up @@ -295,6 +289,14 @@ public SearchSourceBuilder(StreamInput in) throws IOException {
if (in.getVersion().onOrAfter(Version.V_2_13_0)) {
includeNamedQueriesScore = in.readOptionalBoolean();
}
if (in.getVersion().onOrAfter(Version.V_2_13_1)) {
if (in.readBoolean()) {
derivedFieldsObject = in.readMap();
}
if (in.readBoolean()) {
derivedFields = in.readList(DerivedField::new);
}
}
}

@Override
Expand Down Expand Up @@ -323,16 +325,6 @@ public void writeTo(StreamOutput out) throws IOException {
if (hasScriptFields) {
out.writeList(scriptFields);
}
boolean hasDerivedFieldsObject = derivedFieldsObject != null;
out.writeBoolean(hasDerivedFieldsObject);
if (hasDerivedFieldsObject) {
out.writeMap(derivedFieldsObject);
}
boolean hasDerivedFields = derivedFields != null;
out.writeBoolean(hasDerivedFields);
if (hasDerivedFields) {
out.writeList(derivedFields);
}
out.writeVInt(size);
boolean hasSorts = sorts != null;
out.writeBoolean(hasSorts);
Expand Down Expand Up @@ -373,6 +365,18 @@ public void writeTo(StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(Version.V_2_13_0)) {
out.writeOptionalBoolean(includeNamedQueriesScore);
}
if (out.getVersion().onOrAfter(Version.V_2_13_1)) {
boolean hasDerivedFieldsObject = derivedFieldsObject != null;
out.writeBoolean(hasDerivedFieldsObject);
if (hasDerivedFieldsObject) {
out.writeMap(derivedFieldsObject);
}
boolean hasDerivedFields = derivedFields != null;
out.writeBoolean(hasDerivedFields);
if (hasDerivedFields) {
out.writeList(derivedFields);
}
}
}

/**
Expand Down Expand Up @@ -1164,8 +1168,6 @@ private SearchSourceBuilder shallowCopy(
rewrittenBuilder.queryBuilder = queryBuilder;
rewrittenBuilder.rescoreBuilders = rescoreBuilders;
rewrittenBuilder.scriptFields = scriptFields;
rewrittenBuilder.derivedFieldsObject = derivedFieldsObject;
rewrittenBuilder.derivedFields = derivedFields;
rewrittenBuilder.searchAfterBuilder = searchAfterBuilder;
rewrittenBuilder.sliceBuilder = slice;
rewrittenBuilder.size = size;
Expand All @@ -1181,6 +1183,8 @@ private SearchSourceBuilder shallowCopy(
rewrittenBuilder.seqNoAndPrimaryTerm = seqNoAndPrimaryTerm;
rewrittenBuilder.collapse = collapse;
rewrittenBuilder.pointInTimeBuilder = pointInTimeBuilder;
rewrittenBuilder.derivedFieldsObject = derivedFieldsObject;
rewrittenBuilder.derivedFields = derivedFields;
return rewrittenBuilder;
}

Expand Down Expand Up @@ -1267,8 +1271,6 @@ public void parseXContent(XContentParser parser, boolean checkTrailingTokens) th
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
scriptFields.add(new ScriptField(parser));
}
} else if (DERIVED_FIELDS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
derivedFieldsObject = parser.map();
} else if (INDICES_BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
deprecationLogger.deprecate(
"indices_boost_object_format",
Expand Down Expand Up @@ -1330,6 +1332,8 @@ public void parseXContent(XContentParser parser, boolean checkTrailingTokens) th
pointInTimeBuilder = PointInTimeBuilder.fromXContent(parser);
} else if (SEARCH_PIPELINE.match(currentFieldName, parser.getDeprecationHandler())) {
searchPipelineSource = parser.mapOrdered();
} else if (DERIVED_FIELDS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
derivedFieldsObject = parser.map();
} else {
throw new ParsingException(
parser.getTokenLocation(),
Expand Down Expand Up @@ -1483,19 +1487,6 @@ public XContentBuilder innerToXContent(XContentBuilder builder, Params params) t
builder.endObject();
}

if (derivedFieldsObject != null || derivedFields != null) {
builder.startObject(DERIVED_FIELDS_FIELD.getPreferredName());
if (derivedFieldsObject != null) {
builder.map(derivedFieldsObject);
}
if (derivedFields != null) {
for (DerivedField derivedField : derivedFields) {
derivedField.toXContent(builder, params);
}
}
builder.endObject();
}

if (sorts != null) {
builder.startArray(SORT_FIELD.getPreferredName());
for (SortBuilder<?> sort : sorts) {
Expand Down Expand Up @@ -1575,6 +1566,20 @@ public XContentBuilder innerToXContent(XContentBuilder builder, Params params) t
if (searchPipelineSource != null) {
builder.field(SEARCH_PIPELINE.getPreferredName(), searchPipelineSource);
}

if (derivedFieldsObject != null || derivedFields != null) {
builder.startObject(DERIVED_FIELDS_FIELD.getPreferredName());
if (derivedFieldsObject != null) {
builder.map(derivedFieldsObject);
}
if (derivedFields != null) {
for (DerivedField derivedField : derivedFields) {
derivedField.toXContent(builder, params);
}
}
builder.endObject();
}

return builder;
}

Expand Down Expand Up @@ -1834,8 +1839,6 @@ public int hashCode() {
queryBuilder,
rescoreBuilders,
scriptFields,
derivedFieldsObject,
derivedFields,
size,
sorts,
searchAfterBuilder,
Expand All @@ -1852,7 +1855,9 @@ public int hashCode() {
extBuilders,
collapse,
trackTotalHitsUpTo,
pointInTimeBuilder
pointInTimeBuilder,
derivedFieldsObject,
derivedFields
);
}

Expand All @@ -1879,8 +1884,6 @@ public boolean equals(Object obj) {
&& Objects.equals(queryBuilder, other.queryBuilder)
&& Objects.equals(rescoreBuilders, other.rescoreBuilders)
&& Objects.equals(scriptFields, other.scriptFields)
&& Objects.equals(derivedFieldsObject, other.derivedFieldsObject)
&& Objects.equals(derivedFields, other.derivedFields)
&& Objects.equals(size, other.size)
&& Objects.equals(sorts, other.sorts)
&& Objects.equals(searchAfterBuilder, other.searchAfterBuilder)
Expand All @@ -1897,7 +1900,9 @@ public boolean equals(Object obj) {
&& Objects.equals(extBuilders, other.extBuilders)
&& Objects.equals(collapse, other.collapse)
&& Objects.equals(trackTotalHitsUpTo, other.trackTotalHitsUpTo)
&& Objects.equals(pointInTimeBuilder, other.pointInTimeBuilder);
&& Objects.equals(pointInTimeBuilder, other.pointInTimeBuilder)
&& Objects.equals(derivedFieldsObject, other.derivedFieldsObject)
&& Objects.equals(derivedFields, other.derivedFields);
}

@Override
Expand Down

0 comments on commit f40465a

Please sign in to comment.