co.elastic.clients.elasticsearch.indices.CreateIndexRequest Maven / Gradle / Ivy
Show all versions of elasticsearch-java Show documentation
/*
* 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.
*/
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.WaitForActiveShards;
import co.elastic.clients.elasticsearch._types.mapping.TypeMapping;
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 jakarta.json.stream.JsonGenerator;
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;
//----------------------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------------------
//
// This code is generated from the Elasticsearch API specification
// at https://github.com/elastic/elasticsearch-specification
//
// Manual updates to this file will be lost when the code is
// re-generated.
//
// If you find a property that is missing or wrongly typed, please
// open an issue or a PR on the API specification repository.
//
//----------------------------------------------------------------
// typedef: indices.create.Request
/**
* Create an index. Creates a new index.
*
* @see API
* specification
*/
@JsonpDeserializable
public class CreateIndexRequest extends RequestBase implements JsonpSerializable {
private final Map aliases;
private final String index;
@Nullable
private final TypeMapping mappings;
@Nullable
private final Time masterTimeout;
@Nullable
private final IndexSettings settings;
@Nullable
private final Time timeout;
@Nullable
private final WaitForActiveShards waitForActiveShards;
// ---------------------------------------------------------------------------------------------
private CreateIndexRequest(Builder builder) {
this.aliases = ApiTypeHelper.unmodifiable(builder.aliases);
this.index = ApiTypeHelper.requireNonNull(builder.index, this, "index");
this.mappings = builder.mappings;
this.masterTimeout = builder.masterTimeout;
this.settings = builder.settings;
this.timeout = builder.timeout;
this.waitForActiveShards = builder.waitForActiveShards;
}
public static CreateIndexRequest of(Function> fn) {
return fn.apply(new Builder()).build();
}
/**
* Aliases for the index.
*
* API name: {@code aliases}
*/
public final Map aliases() {
return this.aliases;
}
/**
* Required - Name of the index you wish to create.
*
* API name: {@code index}
*/
public final String index() {
return this.index;
}
/**
* Mapping for fields in the index. If specified, this mapping can include:
*
* - Field names
* - Field data types
* - Mapping parameters
*
*
* 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;
}
/**
* Configuration options for the index.
*
* API name: {@code settings}
*/
@Nullable
public final IndexSettings settings() {
return this.settings;
}
/**
* Period to wait for a response. If no response is received before the timeout
* expires, the request fails and returns an error.
*
* API name: {@code timeout}
*/
@Nullable
public final Time timeout() {
return this.timeout;
}
/**
* The number of shard copies that must be active before proceeding with the
* operation. Set to all
or any positive integer up to the total
* number of shards in the index (number_of_replicas+1
).
*
* API name: {@code wait_for_active_shards}
*/
@Nullable
public final WaitForActiveShards waitForActiveShards() {
return this.waitForActiveShards;
}
/**
* 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 (this.mappings != null) {
generator.writeKey("mappings");
this.mappings.serialize(generator, mapper);
}
if (this.settings != null) {
generator.writeKey("settings");
this.settings.serialize(generator, mapper);
}
}
// ---------------------------------------------------------------------------------------------
/**
* Builder for {@link CreateIndexRequest}.
*/
public static class Builder extends RequestBase.AbstractBuilder
implements
ObjectBuilder {
@Nullable
private Map aliases;
private String index;
@Nullable
private TypeMapping mappings;
@Nullable
private Time masterTimeout;
@Nullable
private IndexSettings settings;
@Nullable
private Time timeout;
@Nullable
private WaitForActiveShards waitForActiveShards;
/**
* 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());
}
/**
* Required - Name of the index you wish to create.
*
* API name: {@code index}
*/
public final Builder index(String value) {
this.index = value;
return this;
}
/**
* Mapping for fields in the index. If specified, this mapping can include:
*
* - Field names
* - Field data types
* - Mapping parameters
*
*
* API name: {@code mappings}
*/
public final Builder mappings(@Nullable TypeMapping value) {
this.mappings = value;
return this;
}
/**
* Mapping for fields in the index. If specified, this mapping can include:
*
* - Field names
* - Field data types
* - Mapping parameters
*
*
* 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());
}
/**
* Configuration options for the index.
*
* API name: {@code settings}
*/
public final Builder settings(@Nullable IndexSettings value) {
this.settings = value;
return this;
}
/**
* Configuration options for the index.
*
* API name: {@code settings}
*/
public final Builder settings(Function> fn) {
return this.settings(fn.apply(new IndexSettings.Builder()).build());
}
/**
* Period to wait for a response. If no response is received before the timeout
* expires, the request fails and returns an error.
*
* API name: {@code timeout}
*/
public final Builder timeout(@Nullable Time value) {
this.timeout = value;
return this;
}
/**
* Period to wait for a response. If no response is received before the timeout
* expires, the request fails and returns an error.
*
* API name: {@code timeout}
*/
public final Builder timeout(Function> fn) {
return this.timeout(fn.apply(new Time.Builder()).build());
}
/**
* The number of shard copies that must be active before proceeding with the
* operation. Set to all
or any positive integer up to the total
* number of shards in the index (number_of_replicas+1
).
*
* API name: {@code wait_for_active_shards}
*/
public final Builder waitForActiveShards(@Nullable WaitForActiveShards value) {
this.waitForActiveShards = value;
return this;
}
/**
* The number of shard copies that must be active before proceeding with the
* operation. Set to all
or any positive integer up to the total
* number of shards in the index (number_of_replicas+1
).
*
* API name: {@code wait_for_active_shards}
*/
public final Builder waitForActiveShards(
Function> fn) {
return this.waitForActiveShards(fn.apply(new WaitForActiveShards.Builder()).build());
}
@Override
protected Builder self() {
return this;
}
/**
* Builds a {@link CreateIndexRequest}.
*
* @throws NullPointerException
* if some of the required fields are null.
*/
public CreateIndexRequest build() {
_checkSingleUse();
return new CreateIndexRequest(this);
}
}
// ---------------------------------------------------------------------------------------------
/**
* Json deserializer for {@link CreateIndexRequest}
*/
public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer
.lazy(Builder::new, CreateIndexRequest::setupCreateIndexRequestDeserializer);
protected static void setupCreateIndexRequestDeserializer(ObjectDeserializer op) {
op.add(Builder::aliases, JsonpDeserializer.stringMapDeserializer(Alias._DESERIALIZER), "aliases");
op.add(Builder::mappings, TypeMapping._DESERIALIZER, "mappings");
op.add(Builder::settings, IndexSettings._DESERIALIZER, "settings");
}
// ---------------------------------------------------------------------------------------------
/**
* Endpoint "{@code indices.create}".
*/
public static final Endpoint _ENDPOINT = new SimpleEndpoint<>(
"es/indices.create",
// Request method
request -> {
return "PUT";
},
// Request path
request -> {
final int _index = 1 << 0;
int propsSet = 0;
propsSet |= _index;
if (propsSet == (_index)) {
StringBuilder buf = new StringBuilder();
buf.append("/");
SimpleEndpoint.pathEncode(request.index, buf);
return buf.toString();
}
throw SimpleEndpoint.noPathTemplateFound("path");
},
// Path parameters
request -> {
Map params = new HashMap<>();
final int _index = 1 << 0;
int propsSet = 0;
propsSet |= _index;
if (propsSet == (_index)) {
params.put("index", request.index);
}
return params;
},
// Request parameters
request -> {
Map params = new HashMap<>();
if (request.masterTimeout != null) {
params.put("master_timeout", request.masterTimeout._toJsonString());
}
if (request.waitForActiveShards != null) {
params.put("wait_for_active_shards", request.waitForActiveShards._toJsonString());
}
if (request.timeout != null) {
params.put("timeout", request.timeout._toJsonString());
}
return params;
}, SimpleEndpoint.emptyMap(), true, CreateIndexResponse._DESERIALIZER);
}