Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Maurya <rishabhmaurya05@gmail.com>
  • Loading branch information
rishabhmaurya committed Jun 3, 2024
1 parent e0fb120 commit 6e35862
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
37 changes: 21 additions & 16 deletions server/src/main/java/org/opensearch/index/mapper/DerivedField.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.index.mapper;

import org.opensearch.Version;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
Expand All @@ -30,7 +31,7 @@ public class DerivedField implements Writeable, ToXContentFragment {
private final String type;
private final Script script;
private String sourceIndexedField;
private Map<String, String> properties;
private Map<String, Object> properties;
private Boolean ignoreMalformed;
private String format;

Expand All @@ -44,28 +45,32 @@ public DerivedField(StreamInput in) throws IOException {
name = in.readString();
type = in.readString();
script = new Script(in);
if (in.readBoolean()) {
properties = in.readMap(StreamInput::readString, StreamInput::readString);
if (in.getVersion().onOrAfter(Version.V_2_15_0)) {
if (in.readBoolean()) {
properties = in.readMap();
}
sourceIndexedField = in.readOptionalString();
format = in.readOptionalString();
ignoreMalformed = in.readOptionalBoolean();
}
sourceIndexedField = in.readOptionalString();
format = in.readOptionalString();
ignoreMalformed = in.readOptionalBoolean();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(name);
out.writeString(type);
script.writeTo(out);
if (properties == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeMap(properties, StreamOutput::writeString, StreamOutput::writeString);
if (out.getVersion().onOrAfter(Version.V_2_15_0)) {
if (properties == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeMap(properties);
}
out.writeOptionalString(sourceIndexedField);
out.writeOptionalString(format);
out.writeOptionalBoolean(ignoreMalformed);
}
out.writeOptionalString(sourceIndexedField);
out.writeOptionalString(format);
out.writeOptionalBoolean(ignoreMalformed);
}

@Override
Expand Down Expand Up @@ -101,7 +106,7 @@ public Script getScript() {
return script;
}

public Map<String, String> getProperties() {
public Map<String, Object> getProperties() {
return properties;
}

Expand All @@ -117,7 +122,7 @@ public boolean getIgnoreMalformed() {
return Boolean.TRUE.equals(ignoreMalformed);
}

public void setProperties(Map<String, String> properties) {
public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ public SearchSourceBuilder derivedField(
String name,
String type,
Script script,
Map<String, String> properties,
Map<String, Object> properties,
String sourceIndexedField,
String format,
Boolean ignoreMalformed
Expand Down

0 comments on commit 6e35862

Please sign in to comment.