co.elastic.clients.elasticsearch.indices.PutTemplateRequest Maven / Gradle / Ivy
/*
* 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.indices;
import co.elastic.clients.elasticsearch._types.ErrorResponse;
import co.elastic.clients.elasticsearch._types.RequestBase;
import co.elastic.clients.elasticsearch._types.Time;
import co.elastic.clients.elasticsearch._types.mapping.TypeMapping;
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.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.Integer;
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 javax.annotation.Nullable;
// typedef: indices.put_template.Request
/**
* Creates or updates an index template.
*
* @see API
* specification
*/
@JsonpDeserializable
public class PutTemplateRequest extends RequestBase implements JsonpSerializable {
private final Map aliases;
@Nullable
private final Boolean create;
@Nullable
private final Boolean flatSettings;
private final List indexPatterns;
@Nullable
private final TypeMapping mappings;
@Nullable
private final Time masterTimeout;
private final String name;
@Nullable
private final Integer order;
private final Map settings;
@Nullable
private final Time timeout;
@Nullable
private final Long version;
// ---------------------------------------------------------------------------------------------
private PutTemplateRequest(Builder builder) {
this.aliases = ApiTypeHelper.unmodifiable(builder.aliases);
this.create = builder.create;
this.flatSettings = builder.flatSettings;
this.indexPatterns = ApiTypeHelper.unmodifiable(builder.indexPatterns);
this.mappings = builder.mappings;
this.masterTimeout = builder.masterTimeout;
this.name = ApiTypeHelper.requireNonNull(builder.name, this, "name");
this.order = builder.order;
this.settings = ApiTypeHelper.unmodifiable(builder.settings);
this.timeout = builder.timeout;
this.version = builder.version;
}
public static PutTemplateRequest of(Function> fn) {
return fn.apply(new Builder()).build();
}
/**
* Aliases for the index.
*
* API name: {@code aliases}
*/
public final Map aliases() {
return this.aliases;
}
/**
* If true, this request cannot replace or update existing index templates.
*
* API name: {@code create}
*/
@Nullable
public final Boolean create() {
return this.create;
}
/**
* API name: {@code flat_settings}
*/
@Nullable
public final Boolean flatSettings() {
return this.flatSettings;
}
/**
* Array of wildcard expressions used to match the names of indices during
* creation.
*
* API name: {@code index_patterns}
*/
public final List indexPatterns() {
return this.indexPatterns;
}
/**
* Mapping for fields in the index.
*
* API name: {@code mappings}
*/
@Nullable
public final TypeMapping mappings() {
return this.mappings;
}
/**
* Period to wait for a connection to the master node. If no response is
* received before the timeout expires, the request fails and returns an error.
*
* API name: {@code master_timeout}
*/
@Nullable
public final Time masterTimeout() {
return this.masterTimeout;
}
/**
* Required - The name of the template
*
* API name: {@code name}
*/
public final String name() {
return this.name;
}
/**
* Order in which Elasticsearch applies this template if index matches multiple
* templates.
*
* Templates with lower 'order' values are merged first. Templates with higher
* 'order' values are merged later, overriding templates with lower values.
*
* API name: {@code order}
*/
@Nullable
public final Integer order() {
return this.order;
}
/**
* Configuration options for the index.
*
* API name: {@code settings}
*/
public final Map settings() {
return this.settings;
}
/**
* API name: {@code timeout}
*/
@Nullable
public final Time timeout() {
return this.timeout;
}
/**
* Version number used to manage index templates externally. This number is not
* automatically generated by Elasticsearch.
*
* API name: {@code version}
*/
@Nullable
public final Long version() {
return this.version;
}
/**
* 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 (ApiTypeHelper.isDefined(this.aliases)) {
generator.writeKey("aliases");
generator.writeStartObject();
for (Map.Entry item0 : this.aliases.entrySet()) {
generator.writeKey(item0.getKey());
item0.getValue().serialize(generator, mapper);
}
generator.writeEnd();
}
if (ApiTypeHelper.isDefined(this.indexPatterns)) {
generator.writeKey("index_patterns");
generator.writeStartArray();
for (String item0 : this.indexPatterns) {
generator.write(item0);
}
generator.writeEnd();
}
if (this.mappings != null) {
generator.writeKey("mappings");
this.mappings.serialize(generator, mapper);
}
if (this.order != null) {
generator.writeKey("order");
generator.write(this.order);
}
if (ApiTypeHelper.isDefined(this.settings)) {
generator.writeKey("settings");
generator.writeStartObject();
for (Map.Entry item0 : this.settings.entrySet()) {
generator.writeKey(item0.getKey());
item0.getValue().serialize(generator, mapper);
}
generator.writeEnd();
}
if (this.version != null) {
generator.writeKey("version");
generator.write(this.version);
}
}
// ---------------------------------------------------------------------------------------------
/**
* Builder for {@link PutTemplateRequest}.
*/
public static class Builder extends WithJsonObjectBuilderBase
implements
ObjectBuilder {
@Nullable
private Map aliases;
@Nullable
private Boolean create;
@Nullable
private Boolean flatSettings;
@Nullable
private List indexPatterns;
@Nullable
private TypeMapping mappings;
@Nullable
private Time masterTimeout;
private String name;
@Nullable
private Integer order;
@Nullable
private Map settings;
@Nullable
private Time timeout;
@Nullable
private Long version;
/**
* Aliases for the index.
*
* API name: {@code aliases}
*
* Adds all entries of map
to aliases
.
*/
public final Builder aliases(Map map) {
this.aliases = _mapPutAll(this.aliases, map);
return this;
}
/**
* Aliases for the index.
*
* API name: {@code aliases}
*
* Adds an entry to aliases
.
*/
public final Builder aliases(String key, Alias value) {
this.aliases = _mapPut(this.aliases, key, value);
return this;
}
/**
* Aliases for the index.
*
* API name: {@code aliases}
*
* Adds an entry to aliases
using a builder lambda.
*/
public final Builder aliases(String key, Function> fn) {
return aliases(key, fn.apply(new Alias.Builder()).build());
}
/**
* If true, this request cannot replace or update existing index templates.
*
* API name: {@code create}
*/
public final Builder create(@Nullable Boolean value) {
this.create = value;
return this;
}
/**
* API name: {@code flat_settings}
*/
public final Builder flatSettings(@Nullable Boolean value) {
this.flatSettings = value;
return this;
}
/**
* Array of wildcard expressions used to match the names of indices during
* creation.
*
* API name: {@code index_patterns}
*
* Adds all elements of list
to indexPatterns
.
*/
public final Builder indexPatterns(List list) {
this.indexPatterns = _listAddAll(this.indexPatterns, list);
return this;
}
/**
* Array of wildcard expressions used to match the names of indices during
* creation.
*
* API name: {@code index_patterns}
*
* Adds one or more values to indexPatterns
.
*/
public final Builder indexPatterns(String value, String... values) {
this.indexPatterns = _listAdd(this.indexPatterns, value, values);
return this;
}
/**
* Mapping for fields in the index.
*
* API name: {@code mappings}
*/
public final Builder mappings(@Nullable TypeMapping value) {
this.mappings = value;
return this;
}
/**
* Mapping for fields in the index.
*
* API name: {@code mappings}
*/
public final Builder mappings(Function> fn) {
return this.mappings(fn.apply(new TypeMapping.Builder()).build());
}
/**
* Period to wait for a connection to the master node. If no response is
* received before the timeout expires, the request fails and returns an error.
*
* API name: {@code master_timeout}
*/
public final Builder masterTimeout(@Nullable Time value) {
this.masterTimeout = value;
return this;
}
/**
* Period to wait for a connection to the master node. If no response is
* received before the timeout expires, the request fails and returns an error.
*
* API name: {@code master_timeout}
*/
public final Builder masterTimeout(Function> fn) {
return this.masterTimeout(fn.apply(new Time.Builder()).build());
}
/**
* Required - The name of the template
*
* API name: {@code name}
*/
public final Builder name(String value) {
this.name = value;
return this;
}
/**
* Order in which Elasticsearch applies this template if index matches multiple
* templates.
*
* Templates with lower 'order' values are merged first. Templates with higher
* 'order' values are merged later, overriding templates with lower values.
*
* API name: {@code order}
*/
public final Builder order(@Nullable Integer value) {
this.order = value;
return this;
}
/**
* Configuration options for the index.
*
* API name: {@code settings}
*
* Adds all entries of map
to settings
.
*/
public final Builder settings(Map map) {
this.settings = _mapPutAll(this.settings, map);
return this;
}
/**
* Configuration options for the index.
*
* API name: {@code settings}
*
* Adds an entry to settings
.
*/
public final Builder settings(String key, JsonData value) {
this.settings = _mapPut(this.settings, key, value);
return this;
}
/**
* API name: {@code timeout}
*/
public final Builder timeout(@Nullable Time value) {
this.timeout = value;
return this;
}
/**
* API name: {@code timeout}
*/
public final Builder timeout(Function> fn) {
return this.timeout(fn.apply(new Time.Builder()).build());
}
/**
* Version number used to manage index templates externally. This number is not
* automatically generated by Elasticsearch.
*
* API name: {@code version}
*/
public final Builder version(@Nullable Long value) {
this.version = value;
return this;
}
@Override
protected Builder self() {
return this;
}
/**
* Builds a {@link PutTemplateRequest}.
*
* @throws NullPointerException
* if some of the required fields are null.
*/
public PutTemplateRequest build() {
_checkSingleUse();
return new PutTemplateRequest(this);
}
}
// ---------------------------------------------------------------------------------------------
/**
* Json deserializer for {@link PutTemplateRequest}
*/
public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer
.lazy(Builder::new, PutTemplateRequest::setupPutTemplateRequestDeserializer);
protected static void setupPutTemplateRequestDeserializer(ObjectDeserializer op) {
op.add(Builder::aliases, JsonpDeserializer.stringMapDeserializer(Alias._DESERIALIZER), "aliases");
op.add(Builder::indexPatterns, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()),
"index_patterns");
op.add(Builder::mappings, TypeMapping._DESERIALIZER, "mappings");
op.add(Builder::order, JsonpDeserializer.integerDeserializer(), "order");
op.add(Builder::settings, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "settings");
op.add(Builder::version, JsonpDeserializer.longDeserializer(), "version");
}
// ---------------------------------------------------------------------------------------------
/**
* Endpoint "{@code indices.put_template}".
*/
public static final Endpoint _ENDPOINT = new SimpleEndpoint<>(
"es/indices.put_template",
// Request method
request -> {
return "PUT";
},
// Request path
request -> {
final int _name = 1 << 0;
int propsSet = 0;
propsSet |= _name;
if (propsSet == (_name)) {
StringBuilder buf = new StringBuilder();
buf.append("/_template");
buf.append("/");
SimpleEndpoint.pathEncode(request.name, buf);
return buf.toString();
}
throw SimpleEndpoint.noPathTemplateFound("path");
},
// Request parameters
request -> {
Map params = new HashMap<>();
if (request.masterTimeout != null) {
params.put("master_timeout", request.masterTimeout._toJsonString());
}
if (request.flatSettings != null) {
params.put("flat_settings", String.valueOf(request.flatSettings));
}
if (request.create != null) {
params.put("create", String.valueOf(request.create));
}
if (request.timeout != null) {
params.put("timeout", request.timeout._toJsonString());
}
return params;
}, SimpleEndpoint.emptyMap(), true, PutTemplateResponse._DESERIALIZER);
}