8
8
9
9
package org .opensearch .index .mapper ;
10
10
11
+ import org .opensearch .Version ;
11
12
import org .opensearch .common .annotation .PublicApi ;
12
13
import org .opensearch .core .common .io .stream .StreamInput ;
13
14
import org .opensearch .core .common .io .stream .StreamOutput ;
18
19
import org .opensearch .script .Script ;
19
20
20
21
import java .io .IOException ;
22
+ import java .util .Map ;
21
23
import java .util .Objects ;
22
24
23
25
/**
24
26
* DerivedField representation: expects a name, type and script.
25
27
*/
26
28
@ PublicApi (since = "2.14.0" )
27
29
public class DerivedField implements Writeable , ToXContentFragment {
28
-
29
30
private final String name ;
30
31
private final String type ;
31
32
private final Script script ;
33
+ private String sourceIndexedField ;
34
+ private Map <String , Object > properties ;
35
+ private Boolean ignoreMalformed ;
36
+ private String format ;
32
37
33
38
public DerivedField (String name , String type , Script script ) {
34
39
this .name = name ;
@@ -40,20 +45,51 @@ public DerivedField(StreamInput in) throws IOException {
40
45
name = in .readString ();
41
46
type = in .readString ();
42
47
script = new Script (in );
48
+ if (in .getVersion ().onOrAfter (Version .V_2_15_0 )) {
49
+ if (in .readBoolean ()) {
50
+ properties = in .readMap ();
51
+ }
52
+ sourceIndexedField = in .readOptionalString ();
53
+ format = in .readOptionalString ();
54
+ ignoreMalformed = in .readOptionalBoolean ();
55
+ }
43
56
}
44
57
45
58
@ Override
46
59
public void writeTo (StreamOutput out ) throws IOException {
47
60
out .writeString (name );
48
61
out .writeString (type );
49
62
script .writeTo (out );
63
+ if (out .getVersion ().onOrAfter (Version .V_2_15_0 )) {
64
+ if (properties == null ) {
65
+ out .writeBoolean (false );
66
+ } else {
67
+ out .writeBoolean (true );
68
+ out .writeMap (properties );
69
+ }
70
+ out .writeOptionalString (sourceIndexedField );
71
+ out .writeOptionalString (format );
72
+ out .writeOptionalBoolean (ignoreMalformed );
73
+ }
50
74
}
51
75
52
76
@ Override
53
77
public XContentBuilder toXContent (XContentBuilder builder , ToXContent .Params params ) throws IOException {
54
78
builder .startObject (name );
55
79
builder .field ("type" , type );
56
80
builder .field ("script" , script );
81
+ if (properties != null ) {
82
+ builder .field ("properties" , properties );
83
+ }
84
+ if (sourceIndexedField != null ) {
85
+ builder .field ("source_indexed_field" , sourceIndexedField );
86
+ }
87
+ if (format != null ) {
88
+ builder .field ("format" , format );
89
+ }
90
+ if (ignoreMalformed != null ) {
91
+ builder .field ("ignore_malformed" , ignoreMalformed );
92
+ }
57
93
builder .endObject ();
58
94
return builder ;
59
95
}
@@ -70,9 +106,41 @@ public Script getScript() {
70
106
return script ;
71
107
}
72
108
109
+ public Map <String , Object > getProperties () {
110
+ return properties ;
111
+ }
112
+
113
+ public String getSourceIndexedField () {
114
+ return sourceIndexedField ;
115
+ }
116
+
117
+ public String getFormat () {
118
+ return format ;
119
+ }
120
+
121
+ public boolean getIgnoreMalformed () {
122
+ return Boolean .TRUE .equals (ignoreMalformed );
123
+ }
124
+
125
+ public void setProperties (Map <String , Object > properties ) {
126
+ this .properties = properties ;
127
+ }
128
+
129
+ public void setSourceIndexedField (String sourceIndexedField ) {
130
+ this .sourceIndexedField = sourceIndexedField ;
131
+ }
132
+
133
+ public void setFormat (String format ) {
134
+ this .format = format ;
135
+ }
136
+
137
+ public void setIgnoreMalformed (boolean ignoreMalformed ) {
138
+ this .ignoreMalformed = ignoreMalformed ;
139
+ }
140
+
73
141
@ Override
74
142
public int hashCode () {
75
- return Objects .hash (name , type , script );
143
+ return Objects .hash (name , type , script , sourceIndexedField , properties , ignoreMalformed , format );
76
144
}
77
145
78
146
@ Override
@@ -84,7 +152,12 @@ public boolean equals(Object obj) {
84
152
return false ;
85
153
}
86
154
DerivedField other = (DerivedField ) obj ;
87
- return Objects .equals (name , other .name ) && Objects .equals (type , other .type ) && Objects .equals (script , other .script );
155
+ return Objects .equals (name , other .name )
156
+ && Objects .equals (type , other .type )
157
+ && Objects .equals (script , other .script )
158
+ && Objects .equals (sourceIndexedField , other .sourceIndexedField )
159
+ && Objects .equals (properties , other .properties )
160
+ && Objects .equals (ignoreMalformed , other .ignoreMalformed )
161
+ && Objects .equals (format , other .format );
88
162
}
89
-
90
163
}
0 commit comments