|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package co.elastic.clients.elasticsearch._types.aggregations; |
| 21 | + |
| 22 | +import co.elastic.clients.json.JsonpDeserializable; |
| 23 | +import co.elastic.clients.json.JsonpDeserializer; |
| 24 | +import co.elastic.clients.json.JsonpMapper; |
| 25 | +import co.elastic.clients.json.JsonpSerializable; |
| 26 | +import co.elastic.clients.json.JsonpUtils; |
| 27 | +import co.elastic.clients.json.ObjectBuilderDeserializer; |
| 28 | +import co.elastic.clients.json.ObjectDeserializer; |
| 29 | +import co.elastic.clients.util.ApiTypeHelper; |
| 30 | +import co.elastic.clients.util.ObjectBuilder; |
| 31 | +import jakarta.json.stream.JsonGenerator; |
| 32 | +import java.lang.Double; |
| 33 | +import java.lang.Integer; |
| 34 | +import java.util.Objects; |
| 35 | +import java.util.function.Function; |
| 36 | +import javax.annotation.Nullable; |
| 37 | + |
| 38 | +//---------------------------------------------------------------- |
| 39 | +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. |
| 40 | +//---------------------------------------------------------------- |
| 41 | +// |
| 42 | +// This code is generated from the Elasticsearch API specification |
| 43 | +// at https://github.com/elastic/elasticsearch-specification |
| 44 | +// |
| 45 | +// Manual updates to this file will be lost when the code is |
| 46 | +// re-generated. |
| 47 | +// |
| 48 | +// If you find a property that is missing or wrongly typed, please |
| 49 | +// open an issue or a PR on the API specification repository. |
| 50 | +// |
| 51 | +//---------------------------------------------------------------- |
| 52 | + |
| 53 | +// typedef: _types.aggregations.RandomSamplerAggregation |
| 54 | + |
| 55 | +/** |
| 56 | + * |
| 57 | + * @see <a href= |
| 58 | + * "../../doc-files/api-spec.html#_types.aggregations.RandomSamplerAggregation">API |
| 59 | + * specification</a> |
| 60 | + */ |
| 61 | +@JsonpDeserializable |
| 62 | +public class RandomSamplerAggregation extends BucketAggregationBase implements AggregationVariant, JsonpSerializable { |
| 63 | + private final double probability; |
| 64 | + |
| 65 | + @Nullable |
| 66 | + private final Integer seed; |
| 67 | + |
| 68 | + @Nullable |
| 69 | + private final Integer shardSeed; |
| 70 | + |
| 71 | + // --------------------------------------------------------------------------------------------- |
| 72 | + |
| 73 | + private RandomSamplerAggregation(Builder builder) { |
| 74 | + |
| 75 | + this.probability = ApiTypeHelper.requireNonNull(builder.probability, this, "probability"); |
| 76 | + this.seed = builder.seed; |
| 77 | + this.shardSeed = builder.shardSeed; |
| 78 | + |
| 79 | + } |
| 80 | + |
| 81 | + public static RandomSamplerAggregation of(Function<Builder, ObjectBuilder<RandomSamplerAggregation>> fn) { |
| 82 | + return fn.apply(new Builder()).build(); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Aggregation variant kind. |
| 87 | + */ |
| 88 | + @Override |
| 89 | + public Aggregation.Kind _aggregationKind() { |
| 90 | + return Aggregation.Kind.RandomSampler; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Required - The probability that a document will be included in the aggregated |
| 95 | + * data. Must be greater than 0, less than 0.5, or exactly 1. The lower the |
| 96 | + * probability, the fewer documents are matched. |
| 97 | + * <p> |
| 98 | + * API name: {@code probability} |
| 99 | + */ |
| 100 | + public final double probability() { |
| 101 | + return this.probability; |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * The seed to generate the random sampling of documents. When a seed is |
| 106 | + * provided, the random subset of documents is the same between calls. |
| 107 | + * <p> |
| 108 | + * API name: {@code seed} |
| 109 | + */ |
| 110 | + @Nullable |
| 111 | + public final Integer seed() { |
| 112 | + return this.seed; |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * When combined with seed, setting shard_seed ensures 100% consistent sampling |
| 117 | + * over shards where data is exactly the same. |
| 118 | + * <p> |
| 119 | + * API name: {@code shard_seed} |
| 120 | + */ |
| 121 | + @Nullable |
| 122 | + public final Integer shardSeed() { |
| 123 | + return this.shardSeed; |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Serialize this object to JSON. |
| 128 | + */ |
| 129 | + public void serialize(JsonGenerator generator, JsonpMapper mapper) { |
| 130 | + generator.writeStartObject(); |
| 131 | + serializeInternal(generator, mapper); |
| 132 | + generator.writeEnd(); |
| 133 | + } |
| 134 | + |
| 135 | + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { |
| 136 | + |
| 137 | + generator.writeKey("probability"); |
| 138 | + generator.write(this.probability); |
| 139 | + |
| 140 | + if (this.seed != null) { |
| 141 | + generator.writeKey("seed"); |
| 142 | + generator.write(this.seed); |
| 143 | + |
| 144 | + } |
| 145 | + if (this.shardSeed != null) { |
| 146 | + generator.writeKey("shard_seed"); |
| 147 | + generator.write(this.shardSeed); |
| 148 | + |
| 149 | + } |
| 150 | + |
| 151 | + } |
| 152 | + |
| 153 | + @Override |
| 154 | + public String toString() { |
| 155 | + return JsonpUtils.toString(this); |
| 156 | + } |
| 157 | + |
| 158 | + // --------------------------------------------------------------------------------------------- |
| 159 | + |
| 160 | + /** |
| 161 | + * Builder for {@link RandomSamplerAggregation}. |
| 162 | + */ |
| 163 | + |
| 164 | + public static class Builder extends BucketAggregationBase.AbstractBuilder<Builder> |
| 165 | + implements |
| 166 | + ObjectBuilder<RandomSamplerAggregation> { |
| 167 | + private Double probability; |
| 168 | + |
| 169 | + @Nullable |
| 170 | + private Integer seed; |
| 171 | + |
| 172 | + @Nullable |
| 173 | + private Integer shardSeed; |
| 174 | + |
| 175 | + /** |
| 176 | + * Required - The probability that a document will be included in the aggregated |
| 177 | + * data. Must be greater than 0, less than 0.5, or exactly 1. The lower the |
| 178 | + * probability, the fewer documents are matched. |
| 179 | + * <p> |
| 180 | + * API name: {@code probability} |
| 181 | + */ |
| 182 | + public final Builder probability(double value) { |
| 183 | + this.probability = value; |
| 184 | + return this; |
| 185 | + } |
| 186 | + |
| 187 | + /** |
| 188 | + * The seed to generate the random sampling of documents. When a seed is |
| 189 | + * provided, the random subset of documents is the same between calls. |
| 190 | + * <p> |
| 191 | + * API name: {@code seed} |
| 192 | + */ |
| 193 | + public final Builder seed(@Nullable Integer value) { |
| 194 | + this.seed = value; |
| 195 | + return this; |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * When combined with seed, setting shard_seed ensures 100% consistent sampling |
| 200 | + * over shards where data is exactly the same. |
| 201 | + * <p> |
| 202 | + * API name: {@code shard_seed} |
| 203 | + */ |
| 204 | + public final Builder shardSeed(@Nullable Integer value) { |
| 205 | + this.shardSeed = value; |
| 206 | + return this; |
| 207 | + } |
| 208 | + |
| 209 | + @Override |
| 210 | + protected Builder self() { |
| 211 | + return this; |
| 212 | + } |
| 213 | + |
| 214 | + /** |
| 215 | + * Builds a {@link RandomSamplerAggregation}. |
| 216 | + * |
| 217 | + * @throws NullPointerException |
| 218 | + * if some of the required fields are null. |
| 219 | + */ |
| 220 | + public RandomSamplerAggregation build() { |
| 221 | + _checkSingleUse(); |
| 222 | + |
| 223 | + return new RandomSamplerAggregation(this); |
| 224 | + } |
| 225 | + } |
| 226 | + |
| 227 | + // --------------------------------------------------------------------------------------------- |
| 228 | + |
| 229 | + /** |
| 230 | + * Json deserializer for {@link RandomSamplerAggregation} |
| 231 | + */ |
| 232 | + public static final JsonpDeserializer<RandomSamplerAggregation> _DESERIALIZER = ObjectBuilderDeserializer |
| 233 | + .lazy(Builder::new, RandomSamplerAggregation::setupRandomSamplerAggregationDeserializer); |
| 234 | + |
| 235 | + protected static void setupRandomSamplerAggregationDeserializer( |
| 236 | + ObjectDeserializer<RandomSamplerAggregation.Builder> op) { |
| 237 | + |
| 238 | + op.add(Builder::probability, JsonpDeserializer.doubleDeserializer(), "probability"); |
| 239 | + op.add(Builder::seed, JsonpDeserializer.integerDeserializer(), "seed"); |
| 240 | + op.add(Builder::shardSeed, JsonpDeserializer.integerDeserializer(), "shard_seed"); |
| 241 | + |
| 242 | + } |
| 243 | + |
| 244 | +} |
0 commit comments