-
Notifications
You must be signed in to change notification settings - Fork 223
/
CountRequest.java
704 lines (602 loc) · 17.1 KB
/
CountRequest.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
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
/*
* 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.ExpandWildcard;
import co.elastic.clients.elasticsearch._types.RequestBase;
import co.elastic.clients.elasticsearch._types.query_dsl.Operator;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
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.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 co.elastic.clients.util.WithJsonObjectBuilderBase;
import jakarta.json.stream.JsonGenerator;
import java.lang.Boolean;
import java.lang.Double;
import java.lang.Long;
import java.lang.String;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
// typedef: _global.count.Request
/**
* Returns number of documents matching a query.
*
* @see <a href="../doc-files/api-spec.html#_global.count.Request">API
* specification</a>
*/
@JsonpDeserializable
public class CountRequest extends RequestBase implements JsonpSerializable {
@Nullable
private final Boolean allowNoIndices;
@Nullable
private final Boolean analyzeWildcard;
@Nullable
private final String analyzer;
@Nullable
private final Operator defaultOperator;
@Nullable
private final String df;
private final List<ExpandWildcard> expandWildcards;
@Nullable
private final Boolean ignoreThrottled;
@Nullable
private final Boolean ignoreUnavailable;
private final List<String> index;
@Nullable
private final Boolean lenient;
@Nullable
private final Double minScore;
@Nullable
private final String preference;
@Nullable
private final String q;
@Nullable
private final Query query;
@Nullable
private final String routing;
@Nullable
private final Long terminateAfter;
// ---------------------------------------------------------------------------------------------
private CountRequest(Builder builder) {
this.allowNoIndices = builder.allowNoIndices;
this.analyzeWildcard = builder.analyzeWildcard;
this.analyzer = builder.analyzer;
this.defaultOperator = builder.defaultOperator;
this.df = builder.df;
this.expandWildcards = ApiTypeHelper.unmodifiable(builder.expandWildcards);
this.ignoreThrottled = builder.ignoreThrottled;
this.ignoreUnavailable = builder.ignoreUnavailable;
this.index = ApiTypeHelper.unmodifiable(builder.index);
this.lenient = builder.lenient;
this.minScore = builder.minScore;
this.preference = builder.preference;
this.q = builder.q;
this.query = builder.query;
this.routing = builder.routing;
this.terminateAfter = builder.terminateAfter;
}
public static CountRequest of(Function<Builder, ObjectBuilder<CountRequest>> fn) {
return fn.apply(new Builder()).build();
}
/**
* Whether to ignore if a wildcard indices expression resolves into no concrete
* indices. (This includes <code>_all</code> string or when no indices have been
* specified)
* <p>
* API name: {@code allow_no_indices}
*/
@Nullable
public final Boolean allowNoIndices() {
return this.allowNoIndices;
}
/**
* Specify whether wildcard and prefix queries should be analyzed (default:
* false)
* <p>
* API name: {@code analyze_wildcard}
*/
@Nullable
public final Boolean analyzeWildcard() {
return this.analyzeWildcard;
}
/**
* The analyzer to use for the query string
* <p>
* API name: {@code analyzer}
*/
@Nullable
public final String analyzer() {
return this.analyzer;
}
/**
* The default operator for query string query (AND or OR)
* <p>
* API name: {@code default_operator}
*/
@Nullable
public final Operator defaultOperator() {
return this.defaultOperator;
}
/**
* The field to use as default where no field prefix is given in the query
* string
* <p>
* API name: {@code df}
*/
@Nullable
public final String df() {
return this.df;
}
/**
* Whether to expand wildcard expression to concrete indices that are open,
* closed or both.
* <p>
* API name: {@code expand_wildcards}
*/
public final List<ExpandWildcard> expandWildcards() {
return this.expandWildcards;
}
/**
* Whether specified concrete, expanded or aliased indices should be ignored
* when throttled
* <p>
* API name: {@code ignore_throttled}
*/
@Nullable
public final Boolean ignoreThrottled() {
return this.ignoreThrottled;
}
/**
* Whether specified concrete indices should be ignored when unavailable
* (missing or closed)
* <p>
* API name: {@code ignore_unavailable}
*/
@Nullable
public final Boolean ignoreUnavailable() {
return this.ignoreUnavailable;
}
/**
* A comma-separated list of indices to restrict the results
* <p>
* API name: {@code index}
*/
public final List<String> index() {
return this.index;
}
/**
* Specify whether format-based query failures (such as providing text to a
* numeric field) should be ignored
* <p>
* API name: {@code lenient}
*/
@Nullable
public final Boolean lenient() {
return this.lenient;
}
/**
* Include only documents with a specific <code>_score</code> value in the
* result
* <p>
* API name: {@code min_score}
*/
@Nullable
public final Double minScore() {
return this.minScore;
}
/**
* Specify the node or shard the operation should be performed on (default:
* random)
* <p>
* API name: {@code preference}
*/
@Nullable
public final String preference() {
return this.preference;
}
/**
* Query in the Lucene query string syntax
* <p>
* API name: {@code q}
*/
@Nullable
public final String q() {
return this.q;
}
/**
* API name: {@code query}
*/
@Nullable
public final Query query() {
return this.query;
}
/**
* A comma-separated list of specific routing values
* <p>
* API name: {@code routing}
*/
@Nullable
public final String routing() {
return this.routing;
}
/**
* The maximum count for each shard, upon reaching which the query execution
* will terminate early
* <p>
* API name: {@code terminate_after}
*/
@Nullable
public final Long terminateAfter() {
return this.terminateAfter;
}
/**
* Serialize this object to JSON.
*/
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartObject();
serializeInternal(generator, mapper);
generator.writeEnd();
}
protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
if (this.query != null) {
generator.writeKey("query");
this.query.serialize(generator, mapper);
}
}
// ---------------------------------------------------------------------------------------------
/**
* Builder for {@link CountRequest}.
*/
public static class Builder extends WithJsonObjectBuilderBase<Builder> implements ObjectBuilder<CountRequest> {
@Nullable
private Boolean allowNoIndices;
@Nullable
private Boolean analyzeWildcard;
@Nullable
private String analyzer;
@Nullable
private Operator defaultOperator;
@Nullable
private String df;
@Nullable
private List<ExpandWildcard> expandWildcards;
@Nullable
private Boolean ignoreThrottled;
@Nullable
private Boolean ignoreUnavailable;
@Nullable
private List<String> index;
@Nullable
private Boolean lenient;
@Nullable
private Double minScore;
@Nullable
private String preference;
@Nullable
private String q;
@Nullable
private Query query;
@Nullable
private String routing;
@Nullable
private Long terminateAfter;
/**
* Whether to ignore if a wildcard indices expression resolves into no concrete
* indices. (This includes <code>_all</code> string or when no indices have been
* specified)
* <p>
* API name: {@code allow_no_indices}
*/
public final Builder allowNoIndices(@Nullable Boolean value) {
this.allowNoIndices = value;
return this;
}
/**
* Specify whether wildcard and prefix queries should be analyzed (default:
* false)
* <p>
* API name: {@code analyze_wildcard}
*/
public final Builder analyzeWildcard(@Nullable Boolean value) {
this.analyzeWildcard = value;
return this;
}
/**
* The analyzer to use for the query string
* <p>
* API name: {@code analyzer}
*/
public final Builder analyzer(@Nullable String value) {
this.analyzer = value;
return this;
}
/**
* The default operator for query string query (AND or OR)
* <p>
* API name: {@code default_operator}
*/
public final Builder defaultOperator(@Nullable Operator value) {
this.defaultOperator = value;
return this;
}
/**
* The field to use as default where no field prefix is given in the query
* string
* <p>
* API name: {@code df}
*/
public final Builder df(@Nullable String value) {
this.df = value;
return this;
}
/**
* Whether to expand wildcard expression to concrete indices that are open,
* closed or both.
* <p>
* API name: {@code expand_wildcards}
* <p>
* Adds all elements of <code>list</code> to <code>expandWildcards</code>.
*/
public final Builder expandWildcards(List<ExpandWildcard> list) {
this.expandWildcards = _listAddAll(this.expandWildcards, list);
return this;
}
/**
* Whether to expand wildcard expression to concrete indices that are open,
* closed or both.
* <p>
* API name: {@code expand_wildcards}
* <p>
* Adds one or more values to <code>expandWildcards</code>.
*/
public final Builder expandWildcards(ExpandWildcard value, ExpandWildcard... values) {
this.expandWildcards = _listAdd(this.expandWildcards, value, values);
return this;
}
/**
* Whether specified concrete, expanded or aliased indices should be ignored
* when throttled
* <p>
* API name: {@code ignore_throttled}
*/
public final Builder ignoreThrottled(@Nullable Boolean value) {
this.ignoreThrottled = value;
return this;
}
/**
* Whether specified concrete indices should be ignored when unavailable
* (missing or closed)
* <p>
* API name: {@code ignore_unavailable}
*/
public final Builder ignoreUnavailable(@Nullable Boolean value) {
this.ignoreUnavailable = value;
return this;
}
/**
* A comma-separated list of indices to restrict the results
* <p>
* API name: {@code index}
* <p>
* Adds all elements of <code>list</code> to <code>index</code>.
*/
public final Builder index(List<String> list) {
this.index = _listAddAll(this.index, list);
return this;
}
/**
* A comma-separated list of indices to restrict the results
* <p>
* API name: {@code index}
* <p>
* Adds one or more values to <code>index</code>.
*/
public final Builder index(String value, String... values) {
this.index = _listAdd(this.index, value, values);
return this;
}
/**
* Specify whether format-based query failures (such as providing text to a
* numeric field) should be ignored
* <p>
* API name: {@code lenient}
*/
public final Builder lenient(@Nullable Boolean value) {
this.lenient = value;
return this;
}
/**
* Include only documents with a specific <code>_score</code> value in the
* result
* <p>
* API name: {@code min_score}
*/
public final Builder minScore(@Nullable Double value) {
this.minScore = value;
return this;
}
/**
* Specify the node or shard the operation should be performed on (default:
* random)
* <p>
* API name: {@code preference}
*/
public final Builder preference(@Nullable String value) {
this.preference = value;
return this;
}
/**
* Query in the Lucene query string syntax
* <p>
* API name: {@code q}
*/
public final Builder q(@Nullable String value) {
this.q = value;
return this;
}
/**
* API name: {@code query}
*/
public final Builder query(@Nullable Query value) {
this.query = value;
return this;
}
/**
* API name: {@code query}
*/
public final Builder query(Function<Query.Builder, ObjectBuilder<Query>> fn) {
return this.query(fn.apply(new Query.Builder()).build());
}
/**
* A comma-separated list of specific routing values
* <p>
* API name: {@code routing}
*/
public final Builder routing(@Nullable String value) {
this.routing = value;
return this;
}
/**
* The maximum count for each shard, upon reaching which the query execution
* will terminate early
* <p>
* API name: {@code terminate_after}
*/
public final Builder terminateAfter(@Nullable Long value) {
this.terminateAfter = value;
return this;
}
@Override
protected Builder self() {
return this;
}
/**
* Builds a {@link CountRequest}.
*
* @throws NullPointerException
* if some of the required fields are null.
*/
public CountRequest build() {
_checkSingleUse();
return new CountRequest(this);
}
}
// ---------------------------------------------------------------------------------------------
/**
* Json deserializer for {@link CountRequest}
*/
public static final JsonpDeserializer<CountRequest> _DESERIALIZER = ObjectBuilderDeserializer.lazy(Builder::new,
CountRequest::setupCountRequestDeserializer);
protected static void setupCountRequestDeserializer(ObjectDeserializer<CountRequest.Builder> op) {
op.add(Builder::query, Query._DESERIALIZER, "query");
}
// ---------------------------------------------------------------------------------------------
/**
* Endpoint "{@code count}".
*/
public static final Endpoint<CountRequest, CountResponse, ErrorResponse> _ENDPOINT = new SimpleEndpoint<>(
"es/count",
// Request method
request -> {
return "POST";
},
// Request path
request -> {
final int _index = 1 << 0;
int propsSet = 0;
if (ApiTypeHelper.isDefined(request.index()))
propsSet |= _index;
if (propsSet == 0) {
StringBuilder buf = new StringBuilder();
buf.append("/_count");
return buf.toString();
}
if (propsSet == (_index)) {
StringBuilder buf = new StringBuilder();
buf.append("/");
SimpleEndpoint.pathEncode(request.index.stream().map(v -> v).collect(Collectors.joining(",")), buf);
buf.append("/_count");
return buf.toString();
}
throw SimpleEndpoint.noPathTemplateFound("path");
},
// Request parameters
request -> {
Map<String, String> params = new HashMap<>();
if (request.df != null) {
params.put("df", request.df);
}
if (ApiTypeHelper.isDefined(request.expandWildcards)) {
params.put("expand_wildcards",
request.expandWildcards.stream().map(v -> v.jsonValue()).collect(Collectors.joining(",")));
}
if (request.preference != null) {
params.put("preference", request.preference);
}
if (request.analyzeWildcard != null) {
params.put("analyze_wildcard", String.valueOf(request.analyzeWildcard));
}
if (request.terminateAfter != null) {
params.put("terminate_after", String.valueOf(request.terminateAfter));
}
if (request.lenient != null) {
params.put("lenient", String.valueOf(request.lenient));
}
if (request.minScore != null) {
params.put("min_score", String.valueOf(request.minScore));
}
if (request.routing != null) {
params.put("routing", request.routing);
}
if (request.q != null) {
params.put("q", request.q);
}
if (request.defaultOperator != null) {
params.put("default_operator", request.defaultOperator.jsonValue());
}
if (request.ignoreUnavailable != null) {
params.put("ignore_unavailable", String.valueOf(request.ignoreUnavailable));
}
if (request.allowNoIndices != null) {
params.put("allow_no_indices", String.valueOf(request.allowNoIndices));
}
if (request.analyzer != null) {
params.put("analyzer", request.analyzer);
}
if (request.ignoreThrottled != null) {
params.put("ignore_throttled", String.valueOf(request.ignoreThrottled));
}
return params;
}, SimpleEndpoint.emptyMap(), true, CountResponse._DESERIALIZER);
}