-
Notifications
You must be signed in to change notification settings - Fork 223
/
IndexRequest.java
667 lines (570 loc) · 17.3 KB
/
IndexRequest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
//----------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------
package co.elastic.clients.elasticsearch.core;
import co.elastic.clients.elasticsearch._types.ErrorResponse;
import co.elastic.clients.elasticsearch._types.OpType;
import co.elastic.clients.elasticsearch._types.Refresh;
import co.elastic.clients.elasticsearch._types.RequestBase;
import co.elastic.clients.elasticsearch._types.Time;
import co.elastic.clients.elasticsearch._types.VersionType;
import co.elastic.clients.elasticsearch._types.WaitForActiveShards;
import co.elastic.clients.json.JsonData;
import co.elastic.clients.json.JsonpDeserializable;
import co.elastic.clients.json.JsonpDeserializer;
import co.elastic.clients.json.JsonpMapper;
import co.elastic.clients.json.JsonpSerializable;
import co.elastic.clients.json.JsonpSerializer;
import co.elastic.clients.json.JsonpUtils;
import co.elastic.clients.json.NamedDeserializer;
import co.elastic.clients.json.ObjectBuilderDeserializer;
import co.elastic.clients.json.ObjectDeserializer;
import co.elastic.clients.transport.Endpoint;
import co.elastic.clients.transport.endpoints.SimpleEndpoint;
import co.elastic.clients.util.ApiTypeHelper;
import co.elastic.clients.util.ObjectBuilder;
import jakarta.json.stream.JsonGenerator;
import jakarta.json.stream.JsonParser;
import java.lang.Boolean;
import java.lang.Long;
import java.lang.String;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;
// typedef: _global.index.Request
/**
* Creates or updates a document in an index.
*
* @see <a href="../doc-files/api-spec.html#_global.index.Request">API
* specification</a>
*/
@JsonpDeserializable
public class IndexRequest<TDocument> extends RequestBase implements JsonpSerializable {
@Nullable
private final String id;
@Nullable
private final Long ifPrimaryTerm;
@Nullable
private final Long ifSeqNo;
private final String index;
@Nullable
private final OpType opType;
@Nullable
private final String pipeline;
@Nullable
private final Refresh refresh;
@Nullable
private final Boolean requireAlias;
@Nullable
private final String routing;
@Nullable
private final Time timeout;
@Nullable
private final Long version;
@Nullable
private final VersionType versionType;
@Nullable
private final WaitForActiveShards waitForActiveShards;
private final TDocument document;
@Nullable
private final JsonpSerializer<TDocument> tDocumentSerializer;
// ---------------------------------------------------------------------------------------------
private IndexRequest(Builder<TDocument> builder) {
this.id = builder.id;
this.ifPrimaryTerm = builder.ifPrimaryTerm;
this.ifSeqNo = builder.ifSeqNo;
this.index = ApiTypeHelper.requireNonNull(builder.index, this, "index");
this.opType = builder.opType;
this.pipeline = builder.pipeline;
this.refresh = builder.refresh;
this.requireAlias = builder.requireAlias;
this.routing = builder.routing;
this.timeout = builder.timeout;
this.version = builder.version;
this.versionType = builder.versionType;
this.waitForActiveShards = builder.waitForActiveShards;
this.document = ApiTypeHelper.requireNonNull(builder.document, this, "document");
this.tDocumentSerializer = builder.tDocumentSerializer;
}
public static <TDocument> IndexRequest<TDocument> of(
Function<Builder<TDocument>, ObjectBuilder<IndexRequest<TDocument>>> fn) {
return fn.apply(new Builder<>()).build();
}
/**
* Document ID
* <p>
* API name: {@code id}
*/
@Nullable
public final String id() {
return this.id;
}
/**
* only perform the index operation if the last operation that has changed the
* document has the specified primary term
* <p>
* API name: {@code if_primary_term}
*/
@Nullable
public final Long ifPrimaryTerm() {
return this.ifPrimaryTerm;
}
/**
* only perform the index operation if the last operation that has changed the
* document has the specified sequence number
* <p>
* API name: {@code if_seq_no}
*/
@Nullable
public final Long ifSeqNo() {
return this.ifSeqNo;
}
/**
* Required - The name of the index
* <p>
* API name: {@code index}
*/
public final String index() {
return this.index;
}
/**
* Explicit operation type. Defaults to <code>index</code> for requests with an
* explicit document ID, and to <code>create</code>for requests without an
* explicit document ID
* <p>
* API name: {@code op_type}
*/
@Nullable
public final OpType opType() {
return this.opType;
}
/**
* The pipeline id to preprocess incoming documents with
* <p>
* API name: {@code pipeline}
*/
@Nullable
public final String pipeline() {
return this.pipeline;
}
/**
* If <code>true</code> then refresh the affected shards to make this operation
* visible to search, if <code>wait_for</code> then wait for a refresh to make
* this operation visible to search, if <code>false</code> (the default) then do
* nothing with refreshes.
* <p>
* API name: {@code refresh}
*/
@Nullable
public final Refresh refresh() {
return this.refresh;
}
/**
* When true, requires destination to be an alias. Default is false
* <p>
* API name: {@code require_alias}
*/
@Nullable
public final Boolean requireAlias() {
return this.requireAlias;
}
/**
* Specific routing value
* <p>
* API name: {@code routing}
*/
@Nullable
public final String routing() {
return this.routing;
}
/**
* Explicit operation timeout
* <p>
* API name: {@code timeout}
*/
@Nullable
public final Time timeout() {
return this.timeout;
}
/**
* Explicit version number for concurrency control
* <p>
* API name: {@code version}
*/
@Nullable
public final Long version() {
return this.version;
}
/**
* Specific version type
* <p>
* API name: {@code version_type}
*/
@Nullable
public final VersionType versionType() {
return this.versionType;
}
/**
* Sets the number of shard copies that must be active before proceeding with
* the index operation. Defaults to 1, meaning the primary shard only. Set to
* <code>all</code> for all shard copies, otherwise set to any non-negative
* value less than or equal to the total number of copies for the shard (number
* of replicas + 1)
* <p>
* API name: {@code wait_for_active_shards}
*/
@Nullable
public final WaitForActiveShards waitForActiveShards() {
return this.waitForActiveShards;
}
/**
* Required - Request body.
*/
public final TDocument document() {
return this.document;
}
/**
* Serialize this value to JSON.
*/
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
JsonpUtils.serialize(this.document, generator, tDocumentSerializer, mapper);
}
// ---------------------------------------------------------------------------------------------
/**
* Builder for {@link IndexRequest}.
*/
public static class Builder<TDocument> extends RequestBase.AbstractBuilder<Builder<TDocument>>
implements
ObjectBuilder<IndexRequest<TDocument>> {
@Nullable
private String id;
@Nullable
private Long ifPrimaryTerm;
@Nullable
private Long ifSeqNo;
private String index;
@Nullable
private OpType opType;
@Nullable
private String pipeline;
@Nullable
private Refresh refresh;
@Nullable
private Boolean requireAlias;
@Nullable
private String routing;
@Nullable
private Time timeout;
@Nullable
private Long version;
@Nullable
private VersionType versionType;
@Nullable
private WaitForActiveShards waitForActiveShards;
private TDocument document;
@Nullable
private JsonpSerializer<TDocument> tDocumentSerializer;
/**
* Document ID
* <p>
* API name: {@code id}
*/
public final Builder<TDocument> id(@Nullable String value) {
this.id = value;
return this;
}
/**
* only perform the index operation if the last operation that has changed the
* document has the specified primary term
* <p>
* API name: {@code if_primary_term}
*/
public final Builder<TDocument> ifPrimaryTerm(@Nullable Long value) {
this.ifPrimaryTerm = value;
return this;
}
/**
* only perform the index operation if the last operation that has changed the
* document has the specified sequence number
* <p>
* API name: {@code if_seq_no}
*/
public final Builder<TDocument> ifSeqNo(@Nullable Long value) {
this.ifSeqNo = value;
return this;
}
/**
* Required - The name of the index
* <p>
* API name: {@code index}
*/
public final Builder<TDocument> index(String value) {
this.index = value;
return this;
}
/**
* Explicit operation type. Defaults to <code>index</code> for requests with an
* explicit document ID, and to <code>create</code>for requests without an
* explicit document ID
* <p>
* API name: {@code op_type}
*/
public final Builder<TDocument> opType(@Nullable OpType value) {
this.opType = value;
return this;
}
/**
* The pipeline id to preprocess incoming documents with
* <p>
* API name: {@code pipeline}
*/
public final Builder<TDocument> pipeline(@Nullable String value) {
this.pipeline = value;
return this;
}
/**
* If <code>true</code> then refresh the affected shards to make this operation
* visible to search, if <code>wait_for</code> then wait for a refresh to make
* this operation visible to search, if <code>false</code> (the default) then do
* nothing with refreshes.
* <p>
* API name: {@code refresh}
*/
public final Builder<TDocument> refresh(@Nullable Refresh value) {
this.refresh = value;
return this;
}
/**
* When true, requires destination to be an alias. Default is false
* <p>
* API name: {@code require_alias}
*/
public final Builder<TDocument> requireAlias(@Nullable Boolean value) {
this.requireAlias = value;
return this;
}
/**
* Specific routing value
* <p>
* API name: {@code routing}
*/
public final Builder<TDocument> routing(@Nullable String value) {
this.routing = value;
return this;
}
/**
* Explicit operation timeout
* <p>
* API name: {@code timeout}
*/
public final Builder<TDocument> timeout(@Nullable Time value) {
this.timeout = value;
return this;
}
/**
* Explicit operation timeout
* <p>
* API name: {@code timeout}
*/
public final Builder<TDocument> timeout(Function<Time.Builder, ObjectBuilder<Time>> fn) {
return this.timeout(fn.apply(new Time.Builder()).build());
}
/**
* Explicit version number for concurrency control
* <p>
* API name: {@code version}
*/
public final Builder<TDocument> version(@Nullable Long value) {
this.version = value;
return this;
}
/**
* Specific version type
* <p>
* API name: {@code version_type}
*/
public final Builder<TDocument> versionType(@Nullable VersionType value) {
this.versionType = value;
return this;
}
/**
* Sets the number of shard copies that must be active before proceeding with
* the index operation. Defaults to 1, meaning the primary shard only. Set to
* <code>all</code> for all shard copies, otherwise set to any non-negative
* value less than or equal to the total number of copies for the shard (number
* of replicas + 1)
* <p>
* API name: {@code wait_for_active_shards}
*/
public final Builder<TDocument> waitForActiveShards(@Nullable WaitForActiveShards value) {
this.waitForActiveShards = value;
return this;
}
/**
* Sets the number of shard copies that must be active before proceeding with
* the index operation. Defaults to 1, meaning the primary shard only. Set to
* <code>all</code> for all shard copies, otherwise set to any non-negative
* value less than or equal to the total number of copies for the shard (number
* of replicas + 1)
* <p>
* API name: {@code wait_for_active_shards}
*/
public final Builder<TDocument> waitForActiveShards(
Function<WaitForActiveShards.Builder, ObjectBuilder<WaitForActiveShards>> fn) {
return this.waitForActiveShards(fn.apply(new WaitForActiveShards.Builder()).build());
}
/**
* Required - Request body.
*/
public final Builder<TDocument> document(TDocument value) {
this.document = value;
return this;
}
/**
* Serializer for TDocument. If not set, an attempt will be made to find a
* serializer from the JSON context.
*/
public final Builder<TDocument> tDocumentSerializer(@Nullable JsonpSerializer<TDocument> value) {
this.tDocumentSerializer = value;
return this;
}
@Override
public Builder<TDocument> withJson(JsonParser parser, JsonpMapper mapper) {
JsonpDeserializer<JsonData> tDocumentDeserializer = JsonData._DESERIALIZER;
@SuppressWarnings("unchecked")
TDocument value = (TDocument) tDocumentDeserializer.deserialize(parser, mapper);
return this.document(value);
}
@Override
protected Builder<TDocument> self() {
return this;
}
/**
* Builds a {@link IndexRequest}.
*
* @throws NullPointerException
* if some of the required fields are null.
*/
public IndexRequest<TDocument> build() {
_checkSingleUse();
return new IndexRequest<TDocument>(this);
}
}
/**
* Json deserializer for {@link IndexRequest} based on named deserializers
* provided by the calling {@code JsonMapper}.
*/
public static final JsonpDeserializer<IndexRequest<Object>> _DESERIALIZER = createIndexRequestDeserializer(
new NamedDeserializer<>("co.elastic.clients:Deserializer:_global.index.TDocument"));
public static <TDocument> JsonpDeserializer<IndexRequest<TDocument>> createIndexRequestDeserializer(
JsonpDeserializer<TDocument> tDocumentDeserializer) {
JsonpDeserializer<TDocument> valueDeserializer = tDocumentDeserializer;
return JsonpDeserializer.of(valueDeserializer.acceptedEvents(),
(parser, mapper, event) -> new Builder<TDocument>()
.document(valueDeserializer.deserialize(parser, mapper, event)).build());
}
// ---------------------------------------------------------------------------------------------
/**
* Endpoint "{@code index}".
*/
public static final Endpoint<IndexRequest<?>, IndexResponse, ErrorResponse> _ENDPOINT = new SimpleEndpoint<>(
"es/index",
// Request method
request -> {
final int _index = 1 << 0;
final int _id = 1 << 1;
int propsSet = 0;
propsSet |= _index;
if (request.id() != null)
propsSet |= _id;
if (propsSet == (_index | _id))
return "PUT";
if (propsSet == (_index))
return "POST";
throw SimpleEndpoint.noPathTemplateFound("method");
},
// Request path
request -> {
final int _index = 1 << 0;
final int _id = 1 << 1;
int propsSet = 0;
propsSet |= _index;
if (request.id() != null)
propsSet |= _id;
if (propsSet == (_index | _id)) {
StringBuilder buf = new StringBuilder();
buf.append("/");
SimpleEndpoint.pathEncode(request.index, buf);
buf.append("/_doc");
buf.append("/");
SimpleEndpoint.pathEncode(request.id, buf);
return buf.toString();
}
if (propsSet == (_index)) {
StringBuilder buf = new StringBuilder();
buf.append("/");
SimpleEndpoint.pathEncode(request.index, buf);
buf.append("/_doc");
return buf.toString();
}
throw SimpleEndpoint.noPathTemplateFound("path");
},
// Request parameters
request -> {
Map<String, String> params = new HashMap<>();
if (request.pipeline != null) {
params.put("pipeline", request.pipeline);
}
if (request.routing != null) {
params.put("routing", request.routing);
}
if (request.requireAlias != null) {
params.put("require_alias", String.valueOf(request.requireAlias));
}
if (request.versionType != null) {
params.put("version_type", request.versionType.jsonValue());
}
if (request.ifPrimaryTerm != null) {
params.put("if_primary_term", String.valueOf(request.ifPrimaryTerm));
}
if (request.ifSeqNo != null) {
params.put("if_seq_no", String.valueOf(request.ifSeqNo));
}
if (request.refresh != null) {
params.put("refresh", request.refresh.jsonValue());
}
if (request.waitForActiveShards != null) {
params.put("wait_for_active_shards", request.waitForActiveShards._toJsonString());
}
if (request.opType != null) {
params.put("op_type", request.opType.jsonValue());
}
if (request.version != null) {
params.put("version", String.valueOf(request.version));
}
if (request.timeout != null) {
params.put("timeout", request.timeout._toJsonString());
}
return params;
}, SimpleEndpoint.emptyMap(), r -> r.document(), IndexResponse._DESERIALIZER);
}