24
24
package co .elastic .clients .elasticsearch ._types .aggregations ;
25
25
26
26
import co .elastic .clients .json .ExternallyTaggedUnion ;
27
+ import co .elastic .clients .json .JsonData ;
27
28
import co .elastic .clients .json .JsonEnum ;
28
29
import co .elastic .clients .json .JsonpDeserializable ;
29
30
import co .elastic .clients .json .JsonpDeserializer ;
34
35
import co .elastic .clients .util .ApiTypeHelper ;
35
36
import co .elastic .clients .util .ObjectBuilder ;
36
37
import co .elastic .clients .util .ObjectBuilderBase ;
37
- import co .elastic .clients .util .TaggedUnion ;
38
+ import co .elastic .clients .util .OpenTaggedUnion ;
38
39
import co .elastic .clients .util .TaggedUnionUtils ;
39
40
import jakarta .json .stream .JsonGenerator ;
41
+ import java .lang .Object ;
40
42
import java .util .HashMap ;
41
43
import java .util .Map ;
42
44
import java .util .Objects ;
52
54
* specification</a>
53
55
*/
54
56
55
- public class Aggregate implements TaggedUnion <Aggregate .Kind , AggregateVariant >, JsonpSerializable {
57
+ public class Aggregate implements OpenTaggedUnion <Aggregate .Kind , Object >, JsonpSerializable {
56
58
57
- /**
58
- * {@link Aggregate} variant kinds.
59
- */
60
59
/**
61
60
* {@link Aggregate} variant kinds.
62
61
*
@@ -198,6 +197,9 @@ public enum Kind implements JsonEnum {
198
197
199
198
WeightedAvg ("weighted_avg" ),
200
199
200
+ /** A custom {@code Aggregate} defined by a plugin */
201
+ _Custom (null )
202
+
201
203
;
202
204
203
205
private final String jsonValue ;
@@ -213,36 +215,48 @@ public String jsonValue() {
213
215
}
214
216
215
217
private final Kind _kind ;
216
- private final AggregateVariant _value ;
218
+ private final Object _value ;
217
219
218
220
@ Override
219
221
public final Kind _kind () {
220
222
return _kind ;
221
223
}
222
224
223
225
@ Override
224
- public final AggregateVariant _get () {
226
+ public final Object _get () {
225
227
return _value ;
226
228
}
227
229
228
230
public Aggregate (AggregateVariant value ) {
229
231
230
232
this ._kind = ApiTypeHelper .requireNonNull (value ._aggregateKind (), this , "<variant kind>" );
231
233
this ._value = ApiTypeHelper .requireNonNull (value , this , "<variant value>" );
234
+ this ._customKind = null ;
232
235
233
236
}
234
237
235
238
private Aggregate (Builder builder ) {
236
239
237
240
this ._kind = ApiTypeHelper .requireNonNull (builder ._kind , builder , "<variant kind>" );
238
241
this ._value = ApiTypeHelper .requireNonNull (builder ._value , builder , "<variant value>" );
242
+ this ._customKind = builder ._customKind ;
239
243
240
244
}
241
245
242
246
public static Aggregate of (Function <Builder , ObjectBuilder <Aggregate >> fn ) {
243
247
return fn .apply (new Builder ()).build ();
244
248
}
245
249
250
+ /**
251
+ * Build a custom plugin-defined {@code Aggregate}, given its kind and some JSON
252
+ * data
253
+ */
254
+ public Aggregate (String kind , JsonData value ) {
255
+ this ._kind = Kind ._Custom ;
256
+ this ._value = value ;
257
+ this ._customKind = kind ;
258
+ }
259
+
246
260
/**
247
261
* Is this variant instance of kind {@code adjacency_matrix}?
248
262
*/
@@ -1379,6 +1393,35 @@ public WeightedAvgAggregate weightedAvg() {
1379
1393
return TaggedUnionUtils .get (this , Kind .WeightedAvg );
1380
1394
}
1381
1395
1396
+ @ Nullable
1397
+ private final String _customKind ;
1398
+
1399
+ /**
1400
+ * Is this a custom {@code Aggregate} defined by a plugin?
1401
+ */
1402
+ public boolean _isCustom () {
1403
+ return _kind == Kind ._Custom ;
1404
+ }
1405
+
1406
+ /**
1407
+ * Get the actual kind when {@code _kind()} equals {@link Kind#_Custom}
1408
+ * (plugin-defined variant).
1409
+ */
1410
+ @ Nullable
1411
+ public final String _customKind () {
1412
+ return _customKind ;
1413
+ }
1414
+
1415
+ /**
1416
+ * Get the custom plugin-defined variant value.
1417
+ *
1418
+ * @throws IllegalStateException
1419
+ * if the current variant is not {@link Kind#_Custom}.
1420
+ */
1421
+ public JsonData _custom () {
1422
+ return TaggedUnionUtils .get (this , Kind ._Custom );
1423
+ }
1424
+
1382
1425
@ Override
1383
1426
public void serialize (JsonGenerator generator , JsonpMapper mapper ) {
1384
1427
@@ -1393,7 +1436,8 @@ public String toString() {
1393
1436
1394
1437
public static class Builder extends ObjectBuilderBase implements ObjectBuilder <Aggregate > {
1395
1438
private Kind _kind ;
1396
- private AggregateVariant _value ;
1439
+ private Object _value ;
1440
+ private String _customKind ;
1397
1441
1398
1442
public ObjectBuilder <Aggregate > adjacencyMatrix (AdjacencyMatrixAggregate v ) {
1399
1443
this ._kind = Kind .AdjacencyMatrix ;
@@ -2109,6 +2153,22 @@ public ObjectBuilder<Aggregate> weightedAvg(
2109
2153
return this .weightedAvg (fn .apply (new WeightedAvgAggregate .Builder ()).build ());
2110
2154
}
2111
2155
2156
+ /**
2157
+ * Define this {@code Aggregate} as a plugin-defined variant.
2158
+ *
2159
+ * @param name
2160
+ * the plugin-defined identifier
2161
+ * @param data
2162
+ * the data for this custom {@code Aggregate}. It is converted
2163
+ * internally to {@link JsonData}.
2164
+ */
2165
+ public ObjectBuilder <Aggregate > _custom (String name , Object data ) {
2166
+ this ._kind = Kind ._Custom ;
2167
+ this ._customKind = name ;
2168
+ this ._value = JsonData .of (data );
2169
+ return this ;
2170
+ }
2171
+
2112
2172
public Aggregate build () {
2113
2173
_checkSingleUse ();
2114
2174
return new Aggregate (this );
@@ -2187,7 +2247,7 @@ public Aggregate build() {
2187
2247
deserializers .put ("variable_width_histogram" , VariableWidthHistogramAggregate ._DESERIALIZER );
2188
2248
deserializers .put ("weighted_avg" , WeightedAvgAggregate ._DESERIALIZER );
2189
2249
2190
- _TYPED_KEYS_DESERIALIZER = new ExternallyTaggedUnion .Deserializer <>(deserializers ,
2191
- ( name , value ) -> new Aggregate ( value ) ).typedKeys ();
2250
+ _TYPED_KEYS_DESERIALIZER = new ExternallyTaggedUnion .Deserializer <>(deserializers , Aggregate :: new ,
2251
+ Aggregate :: new ).typedKeys ();
2192
2252
}
2193
2253
}
0 commit comments