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

co.elastic.clients.elasticsearch.core.SearchTemplateRequest 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.ExpandWildcard;
import co.elastic.clients.elasticsearch._types.RequestBase;
import co.elastic.clients.elasticsearch._types.SearchType;
import co.elastic.clients.elasticsearch._types.Time;
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 jakarta.json.stream.JsonGenerator;
import java.lang.Boolean;
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.search_template.Request

/**
 * Run a search with a search template.
 * 
 * @see API
 *      specification
 */
@JsonpDeserializable
public class SearchTemplateRequest extends RequestBase implements JsonpSerializable {
	@Nullable
	private final Boolean allowNoIndices;

	@Nullable
	private final Boolean ccsMinimizeRoundtrips;

	private final List expandWildcards;

	@Nullable
	private final Boolean explain;

	@Nullable
	private final String id;

	@Nullable
	private final Boolean ignoreThrottled;

	@Nullable
	private final Boolean ignoreUnavailable;

	private final List index;

	private final Map params;

	@Nullable
	private final String preference;

	@Nullable
	private final Boolean profile;

	@Nullable
	private final String routing;

	@Nullable
	private final Time scroll;

	@Nullable
	private final SearchType searchType;

	@Nullable
	private final String source;

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

	private SearchTemplateRequest(Builder builder) {

		this.allowNoIndices = builder.allowNoIndices;
		this.ccsMinimizeRoundtrips = builder.ccsMinimizeRoundtrips;
		this.expandWildcards = ApiTypeHelper.unmodifiable(builder.expandWildcards);
		this.explain = builder.explain;
		this.id = builder.id;
		this.ignoreThrottled = builder.ignoreThrottled;
		this.ignoreUnavailable = builder.ignoreUnavailable;
		this.index = ApiTypeHelper.unmodifiable(builder.index);
		this.params = ApiTypeHelper.unmodifiable(builder.params);
		this.preference = builder.preference;
		this.profile = builder.profile;
		this.routing = builder.routing;
		this.scroll = builder.scroll;
		this.searchType = builder.searchType;
		this.source = builder.source;

	}

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

	/**
	 * If false, the request returns an error if any wildcard
	 * expression, index alias, or _all value targets only missing or
	 * closed indices. This behavior applies even if the request targets other open
	 * indices. For example, a request targeting foo*,bar* returns an
	 * error if an index starts with foo but no index starts with
	 * bar.
	 * 

* API name: {@code allow_no_indices} */ @Nullable public final Boolean allowNoIndices() { return this.allowNoIndices; } /** * If true, network round-trips are minimized for cross-cluster * search requests. *

* API name: {@code ccs_minimize_roundtrips} */ @Nullable public final Boolean ccsMinimizeRoundtrips() { return this.ccsMinimizeRoundtrips; } /** * Type of index that wildcard patterns can match. If the request can target * data streams, this argument determines whether wildcard expressions match * hidden data streams. Supports comma-separated values, such as * open,hidden. Valid values are: all, * open, closed, hidden, * none. *

* API name: {@code expand_wildcards} */ public final List expandWildcards() { return this.expandWildcards; } /** * If true, returns detailed information about score calculation as * part of each hit. *

* API name: {@code explain} */ @Nullable public final Boolean explain() { return this.explain; } /** * ID of the search template to use. If no source is specified, this parameter * is required. *

* API name: {@code id} */ @Nullable public final String id() { return this.id; } /** * If true, specified concrete, expanded, or aliased indices are * not included in the response when throttled. *

* API name: {@code ignore_throttled} */ @Nullable public final Boolean ignoreThrottled() { return this.ignoreThrottled; } /** * If false, the request returns an error if it targets a missing * or closed index. *

* API name: {@code ignore_unavailable} */ @Nullable public final Boolean ignoreUnavailable() { return this.ignoreUnavailable; } /** * Comma-separated list of data streams, indices, and aliases to search. * Supports wildcards (*). *

* API name: {@code index} */ public final List index() { return this.index; } /** * Key-value pairs used to replace Mustache variables in the template. The key * is the variable name. The value is the variable value. *

* API name: {@code params} */ public final Map params() { return this.params; } /** * 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 query execution is profiled. *

* API name: {@code profile} */ @Nullable public final Boolean profile() { return this.profile; } /** * Custom value used to route operations to a specific shard. *

* API name: {@code routing} */ @Nullable public final String routing() { return this.routing; } /** * Specifies how long a consistent view of the index should be maintained for * scrolled search. *

* API name: {@code scroll} */ @Nullable public final Time scroll() { return this.scroll; } /** * The type of the search operation. *

* API name: {@code search_type} */ @Nullable public final SearchType searchType() { return this.searchType; } /** * An inline search template. Supports the same parameters as the search API's * request body. Also supports Mustache variables. If no id is specified, this * parameter is required. *

* API name: {@code source} */ @Nullable public final String source() { return this.source; } /** * 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.explain != null) { generator.writeKey("explain"); generator.write(this.explain); } if (this.id != null) { generator.writeKey("id"); generator.write(this.id); } if (ApiTypeHelper.isDefined(this.params)) { generator.writeKey("params"); generator.writeStartObject(); for (Map.Entry item0 : this.params.entrySet()) { generator.writeKey(item0.getKey()); item0.getValue().serialize(generator, mapper); } generator.writeEnd(); } if (this.profile != null) { generator.writeKey("profile"); generator.write(this.profile); } if (this.source != null) { generator.writeKey("source"); generator.write(this.source); } } // --------------------------------------------------------------------------------------------- /** * Builder for {@link SearchTemplateRequest}. */ public static class Builder extends RequestBase.AbstractBuilder implements ObjectBuilder { @Nullable private Boolean allowNoIndices; @Nullable private Boolean ccsMinimizeRoundtrips; @Nullable private List expandWildcards; @Nullable private Boolean explain; @Nullable private String id; @Nullable private Boolean ignoreThrottled; @Nullable private Boolean ignoreUnavailable; @Nullable private List index; @Nullable private Map params; @Nullable private String preference; @Nullable private Boolean profile; @Nullable private String routing; @Nullable private Time scroll; @Nullable private SearchType searchType; @Nullable private String source; /** * If false, the request returns an error if any wildcard * expression, index alias, or _all value targets only missing or * closed indices. This behavior applies even if the request targets other open * indices. For example, a request targeting foo*,bar* returns an * error if an index starts with foo but no index starts with * bar. *

* API name: {@code allow_no_indices} */ public final Builder allowNoIndices(@Nullable Boolean value) { this.allowNoIndices = value; return this; } /** * If true, network round-trips are minimized for cross-cluster * search requests. *

* API name: {@code ccs_minimize_roundtrips} */ public final Builder ccsMinimizeRoundtrips(@Nullable Boolean value) { this.ccsMinimizeRoundtrips = value; return this; } /** * Type of index that wildcard patterns can match. If the request can target * data streams, this argument determines whether wildcard expressions match * hidden data streams. Supports comma-separated values, such as * open,hidden. Valid values are: all, * open, closed, hidden, * none. *

* API name: {@code expand_wildcards} *

* Adds all elements of list to expandWildcards. */ public final Builder expandWildcards(List list) { this.expandWildcards = _listAddAll(this.expandWildcards, list); return this; } /** * Type of index that wildcard patterns can match. If the request can target * data streams, this argument determines whether wildcard expressions match * hidden data streams. Supports comma-separated values, such as * open,hidden. Valid values are: all, * open, closed, hidden, * none. *

* API name: {@code expand_wildcards} *

* Adds one or more values to expandWildcards. */ public final Builder expandWildcards(ExpandWildcard value, ExpandWildcard... values) { this.expandWildcards = _listAdd(this.expandWildcards, value, values); return this; } /** * If true, returns detailed information about score calculation as * part of each hit. *

* API name: {@code explain} */ public final Builder explain(@Nullable Boolean value) { this.explain = value; return this; } /** * ID of the search template to use. If no source is specified, this parameter * is required. *

* API name: {@code id} */ public final Builder id(@Nullable String value) { this.id = value; return this; } /** * If true, specified concrete, expanded, or aliased indices are * not included in the response when throttled. *

* API name: {@code ignore_throttled} */ public final Builder ignoreThrottled(@Nullable Boolean value) { this.ignoreThrottled = value; return this; } /** * If false, the request returns an error if it targets a missing * or closed index. *

* API name: {@code ignore_unavailable} */ public final Builder ignoreUnavailable(@Nullable Boolean value) { this.ignoreUnavailable = value; return this; } /** * Comma-separated list of data streams, indices, and aliases to search. * Supports wildcards (*). *

* API name: {@code index} *

* Adds all elements of list to index. */ public final Builder index(List list) { this.index = _listAddAll(this.index, list); return this; } /** * Comma-separated list of data streams, indices, and aliases to search. * Supports wildcards (*). *

* API name: {@code index} *

* Adds one or more values to index. */ public final Builder index(String value, String... values) { this.index = _listAdd(this.index, value, values); return this; } /** * Key-value pairs used to replace Mustache variables in the template. The key * is the variable name. The value is the variable value. *

* API name: {@code params} *

* Adds all entries of map to params. */ public final Builder params(Map map) { this.params = _mapPutAll(this.params, map); return this; } /** * Key-value pairs used to replace Mustache variables in the template. The key * is the variable name. The value is the variable value. *

* API name: {@code params} *

* Adds an entry to params. */ public final Builder params(String key, JsonData value) { this.params = _mapPut(this.params, key, 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 query execution is profiled. *

* API name: {@code profile} */ public final Builder profile(@Nullable Boolean value) { this.profile = value; return this; } /** * Custom value used to route operations to a specific shard. *

* API name: {@code routing} */ public final Builder routing(@Nullable String value) { this.routing = value; return this; } /** * Specifies how long a consistent view of the index should be maintained for * scrolled search. *

* API name: {@code scroll} */ public final Builder scroll(@Nullable Time value) { this.scroll = value; return this; } /** * Specifies how long a consistent view of the index should be maintained for * scrolled search. *

* API name: {@code scroll} */ public final Builder scroll(Function> fn) { return this.scroll(fn.apply(new Time.Builder()).build()); } /** * The type of the search operation. *

* API name: {@code search_type} */ public final Builder searchType(@Nullable SearchType value) { this.searchType = value; return this; } /** * An inline search template. Supports the same parameters as the search API's * request body. Also supports Mustache variables. If no id is specified, this * parameter is required. *

* API name: {@code source} */ public final Builder source(@Nullable String value) { this.source = value; return this; } @Override protected Builder self() { return this; } /** * Builds a {@link SearchTemplateRequest}. * * @throws NullPointerException * if some of the required fields are null. */ public SearchTemplateRequest build() { _checkSingleUse(); return new SearchTemplateRequest(this); } } // --------------------------------------------------------------------------------------------- /** * Json deserializer for {@link SearchTemplateRequest} */ public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer .lazy(Builder::new, SearchTemplateRequest::setupSearchTemplateRequestDeserializer); protected static void setupSearchTemplateRequestDeserializer(ObjectDeserializer op) { op.add(Builder::explain, JsonpDeserializer.booleanDeserializer(), "explain"); op.add(Builder::id, JsonpDeserializer.stringDeserializer(), "id"); op.add(Builder::params, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "params"); op.add(Builder::profile, JsonpDeserializer.booleanDeserializer(), "profile"); op.add(Builder::source, JsonpDeserializer.stringDeserializer(), "source"); } // --------------------------------------------------------------------------------------------- /** * Endpoint "{@code search_template}". */ public static final SimpleEndpoint _ENDPOINT = new SimpleEndpoint<>("es/search_template", // 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("/_search"); buf.append("/template"); 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("/_search"); buf.append("/template"); return buf.toString(); } throw SimpleEndpoint.noPathTemplateFound("path"); }, // Path parameters request -> { Map params = new HashMap<>(); final int _index = 1 << 0; int propsSet = 0; if (ApiTypeHelper.isDefined(request.index())) propsSet |= _index; if (propsSet == 0) { } if (propsSet == (_index)) { params.put("index", request.index.stream().map(v -> v).collect(Collectors.joining(","))); } return params; }, // Request parameters request -> { Map params = new HashMap<>(); params.put("typed_keys", "true"); 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.scroll != null) { params.put("scroll", request.scroll._toJsonString()); } if (request.searchType != null) { params.put("search_type", request.searchType.jsonValue()); } if (request.ccsMinimizeRoundtrips != null) { params.put("ccs_minimize_roundtrips", String.valueOf(request.ccsMinimizeRoundtrips)); } if (request.routing != null) { params.put("routing", request.routing); } 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.ignoreThrottled != null) { params.put("ignore_throttled", String.valueOf(request.ignoreThrottled)); } return params; }, SimpleEndpoint.emptyMap(), true, SearchTemplateResponse._DESERIALIZER); /** * Create an "{@code search_template}" endpoint. */ public static Endpoint, ErrorResponse> createSearchTemplateEndpoint( JsonpDeserializer tDocumentDeserializer) { return _ENDPOINT.withResponseDeserializer( SearchTemplateResponse.createSearchTemplateResponseDeserializer(tDocumentDeserializer)); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy