All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.elastic.clients.elasticsearch.core.ExistsRequest Maven / Gradle / Ivy

The newest version!
/*
 * 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.core;

import co.elastic.clients.elasticsearch._types.ErrorResponse;
import co.elastic.clients.elasticsearch._types.RequestBase;
import co.elastic.clients.elasticsearch._types.VersionType;
import co.elastic.clients.elasticsearch.core.search.SourceConfigParam;
import co.elastic.clients.json.JsonpDeserializable;
import co.elastic.clients.json.JsonpDeserializer;
import co.elastic.clients.json.ObjectBuilderDeserializer;
import co.elastic.clients.json.ObjectDeserializer;
import co.elastic.clients.transport.Endpoint;
import co.elastic.clients.transport.endpoints.BooleanEndpoint;
import co.elastic.clients.transport.endpoints.BooleanResponse;
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.Boolean;
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;

//----------------------------------------------------------------
//       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: _global.exists.Request

/**
 * Check a document. Checks if a specified document exists.
 * 
 * @see API
 *      specification
 */

public class ExistsRequest extends RequestBase {
	@Nullable
	private final SourceConfigParam source;

	private final List sourceExcludes;

	private final List sourceIncludes;

	private final String id;

	private final String index;

	@Nullable
	private final String preference;

	@Nullable
	private final Boolean realtime;

	@Nullable
	private final Boolean refresh;

	@Nullable
	private final String routing;

	private final List storedFields;

	@Nullable
	private final Long version;

	@Nullable
	private final VersionType versionType;

	// ---------------------------------------------------------------------------------------------

	private ExistsRequest(Builder builder) {

		this.source = builder.source;
		this.sourceExcludes = ApiTypeHelper.unmodifiable(builder.sourceExcludes);
		this.sourceIncludes = ApiTypeHelper.unmodifiable(builder.sourceIncludes);
		this.id = ApiTypeHelper.requireNonNull(builder.id, this, "id");
		this.index = ApiTypeHelper.requireNonNull(builder.index, this, "index");
		this.preference = builder.preference;
		this.realtime = builder.realtime;
		this.refresh = builder.refresh;
		this.routing = builder.routing;
		this.storedFields = ApiTypeHelper.unmodifiable(builder.storedFields);
		this.version = builder.version;
		this.versionType = builder.versionType;

	}

	public static ExistsRequest of(Function> fn) {
		return fn.apply(new Builder()).build();
	}

	/**
	 * true or false to return the _source
	 * field or not, or a list of fields to return.
	 * 

* API name: {@code _source} */ @Nullable public final SourceConfigParam source() { return this.source; } /** * A comma-separated list of source fields to exclude in the response. *

* API name: {@code _source_excludes} */ public final List sourceExcludes() { return this.sourceExcludes; } /** * A comma-separated list of source fields to include in the response. *

* API name: {@code _source_includes} */ public final List sourceIncludes() { return this.sourceIncludes; } /** * Required - Identifier of the document. *

* API name: {@code id} */ public final String id() { return this.id; } /** * Required - Comma-separated list of data streams, indices, and aliases. * Supports wildcards (*). *

* API name: {@code index} */ public final String index() { return this.index; } /** * Specifies the node or shard the operation should be performed on. Random by * default. *

* API name: {@code preference} */ @Nullable public final String preference() { return this.preference; } /** * If true, the request is real-time as opposed to near-real-time. *

* API name: {@code realtime} */ @Nullable public final Boolean realtime() { return this.realtime; } /** * If true, Elasticsearch refreshes all shards involved in the * delete by query after the request completes. *

* API name: {@code refresh} */ @Nullable public final Boolean refresh() { return this.refresh; } /** * Target the specified primary shard. *

* API name: {@code routing} */ @Nullable public final String routing() { return this.routing; } /** * List of stored fields to return as part of a hit. If no fields are specified, * no stored fields are included in the response. If this field is specified, * the _source parameter defaults to false. *

* API name: {@code stored_fields} */ public final List storedFields() { return this.storedFields; } /** * Explicit version number for concurrency control. The specified version must * match the current version of the document for the request to succeed. *

* API name: {@code version} */ @Nullable public final Long version() { return this.version; } /** * Specific version type: external, external_gte. *

* API name: {@code version_type} */ @Nullable public final VersionType versionType() { return this.versionType; } // --------------------------------------------------------------------------------------------- /** * Builder for {@link ExistsRequest}. */ public static class Builder extends RequestBase.AbstractBuilder implements ObjectBuilder { @Nullable private SourceConfigParam source; @Nullable private List sourceExcludes; @Nullable private List sourceIncludes; private String id; private String index; @Nullable private String preference; @Nullable private Boolean realtime; @Nullable private Boolean refresh; @Nullable private String routing; @Nullable private List storedFields; @Nullable private Long version; @Nullable private VersionType versionType; /** * true or false to return the _source * field or not, or a list of fields to return. *

* API name: {@code _source} */ public final Builder source(@Nullable SourceConfigParam value) { this.source = value; return this; } /** * true or false to return the _source * field or not, or a list of fields to return. *

* API name: {@code _source} */ public final Builder source(Function> fn) { return this.source(fn.apply(new SourceConfigParam.Builder()).build()); } /** * A comma-separated list of source fields to exclude in the response. *

* API name: {@code _source_excludes} *

* Adds all elements of list to sourceExcludes. */ public final Builder sourceExcludes(List list) { this.sourceExcludes = _listAddAll(this.sourceExcludes, list); return this; } /** * A comma-separated list of source fields to exclude in the response. *

* API name: {@code _source_excludes} *

* Adds one or more values to sourceExcludes. */ public final Builder sourceExcludes(String value, String... values) { this.sourceExcludes = _listAdd(this.sourceExcludes, value, values); return this; } /** * A comma-separated list of source fields to include in the response. *

* API name: {@code _source_includes} *

* Adds all elements of list to sourceIncludes. */ public final Builder sourceIncludes(List list) { this.sourceIncludes = _listAddAll(this.sourceIncludes, list); return this; } /** * A comma-separated list of source fields to include in the response. *

* API name: {@code _source_includes} *

* Adds one or more values to sourceIncludes. */ public final Builder sourceIncludes(String value, String... values) { this.sourceIncludes = _listAdd(this.sourceIncludes, value, values); return this; } /** * Required - Identifier of the document. *

* API name: {@code id} */ public final Builder id(String value) { this.id = value; return this; } /** * Required - Comma-separated list of data streams, indices, and aliases. * Supports wildcards (*). *

* API name: {@code index} */ public final Builder index(String value) { this.index = value; return this; } /** * Specifies the node or shard the operation should be performed on. Random by * default. *

* API name: {@code preference} */ public final Builder preference(@Nullable String value) { this.preference = value; return this; } /** * If true, the request is real-time as opposed to near-real-time. *

* API name: {@code realtime} */ public final Builder realtime(@Nullable Boolean value) { this.realtime = value; return this; } /** * If true, Elasticsearch refreshes all shards involved in the * delete by query after the request completes. *

* API name: {@code refresh} */ public final Builder refresh(@Nullable Boolean value) { this.refresh = value; return this; } /** * Target the specified primary shard. *

* API name: {@code routing} */ public final Builder routing(@Nullable String value) { this.routing = value; return this; } /** * List of stored fields to return as part of a hit. If no fields are specified, * no stored fields are included in the response. If this field is specified, * the _source parameter defaults to false. *

* API name: {@code stored_fields} *

* Adds all elements of list to storedFields. */ public final Builder storedFields(List list) { this.storedFields = _listAddAll(this.storedFields, list); return this; } /** * List of stored fields to return as part of a hit. If no fields are specified, * no stored fields are included in the response. If this field is specified, * the _source parameter defaults to false. *

* API name: {@code stored_fields} *

* Adds one or more values to storedFields. */ public final Builder storedFields(String value, String... values) { this.storedFields = _listAdd(this.storedFields, value, values); return this; } /** * Explicit version number for concurrency control. The specified version must * match the current version of the document for the request to succeed. *

* API name: {@code version} */ public final Builder version(@Nullable Long value) { this.version = value; return this; } /** * Specific version type: external, external_gte. *

* API name: {@code version_type} */ public final Builder versionType(@Nullable VersionType value) { this.versionType = value; return this; } @Override protected Builder self() { return this; } /** * Builds a {@link ExistsRequest}. * * @throws NullPointerException * if some of the required fields are null. */ public ExistsRequest build() { _checkSingleUse(); return new ExistsRequest(this); } } // --------------------------------------------------------------------------------------------- /** * Endpoint "{@code exists}". */ public static final Endpoint _ENDPOINT = new BooleanEndpoint<>( "es/exists", // Request method request -> { return "HEAD"; }, // Request path request -> { final int _index = 1 << 0; final int _id = 1 << 1; int propsSet = 0; propsSet |= _index; 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(); } throw SimpleEndpoint.noPathTemplateFound("path"); }, // Path parameters request -> { Map params = new HashMap<>(); final int _index = 1 << 0; final int _id = 1 << 1; int propsSet = 0; propsSet |= _index; propsSet |= _id; if (propsSet == (_index | _id)) { params.put("index", request.index); params.put("id", request.id); } return params; }, // Request parameters request -> { Map params = new HashMap<>(); if (request.routing != null) { params.put("routing", request.routing); } if (request.realtime != null) { params.put("realtime", String.valueOf(request.realtime)); } if (request.versionType != null) { params.put("version_type", request.versionType.jsonValue()); } if (ApiTypeHelper.isDefined(request.storedFields)) { params.put("stored_fields", request.storedFields.stream().map(v -> v).collect(Collectors.joining(","))); } if (request.preference != null) { params.put("preference", request.preference); } if (request.refresh != null) { params.put("refresh", String.valueOf(request.refresh)); } if (request.source != null) { params.put("_source", request.source._toJsonString()); } if (ApiTypeHelper.isDefined(request.sourceExcludes)) { params.put("_source_excludes", request.sourceExcludes.stream().map(v -> v).collect(Collectors.joining(","))); } if (ApiTypeHelper.isDefined(request.sourceIncludes)) { params.put("_source_includes", request.sourceIncludes.stream().map(v -> v).collect(Collectors.joining(","))); } if (request.version != null) { params.put("version", String.valueOf(request.version)); } return params; }, SimpleEndpoint.emptyMap(), false, null); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy