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

co.elastic.clients.elasticsearch.core.MsearchTemplateRequest 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.SearchType;
import co.elastic.clients.elasticsearch.core.msearch_template.RequestItem;
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.NdJsonpSerializable;
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.Long;
import java.lang.String;
import java.util.HashMap;
import java.util.Iterator;
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.msearch_template.Request

/**
 * Run multiple templated searches.
 * 
 * @see API
 *      specification
 */

public class MsearchTemplateRequest extends RequestBase implements NdJsonpSerializable, JsonpSerializable {
	@Nullable
	private final Boolean ccsMinimizeRoundtrips;

	private final List index;

	@Nullable
	private final Long maxConcurrentSearches;

	@Nullable
	private final SearchType searchType;

	private final List searchTemplates;

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

	private MsearchTemplateRequest(Builder builder) {

		this.ccsMinimizeRoundtrips = builder.ccsMinimizeRoundtrips;
		this.index = ApiTypeHelper.unmodifiable(builder.index);
		this.maxConcurrentSearches = builder.maxConcurrentSearches;
		this.searchType = builder.searchType;
		this.searchTemplates = ApiTypeHelper.unmodifiableRequired(builder.searchTemplates, this, "searchTemplates");

	}

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

	@Override
	public Iterator _serializables() {
		return this.searchTemplates.iterator();
	}
	/**
	 * 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; } /** * Comma-separated list of data streams, indices, and aliases to search. * Supports wildcards (*). To search all data streams and indices, * omit this parameter or use *. *

* API name: {@code index} */ public final List index() { return this.index; } /** * Maximum number of concurrent searches the API can run. *

* API name: {@code max_concurrent_searches} */ @Nullable public final Long maxConcurrentSearches() { return this.maxConcurrentSearches; } /** * The type of the search operation. Available options: * query_then_fetch, dfs_query_then_fetch. *

* API name: {@code search_type} */ @Nullable public final SearchType searchType() { return this.searchType; } /** * Required - Request body. */ public final List searchTemplates() { return this.searchTemplates; } /** * Serialize this value to JSON. */ public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartArray(); for (RequestItem item0 : this.searchTemplates) { item0.serialize(generator, mapper); } generator.writeEnd(); } // --------------------------------------------------------------------------------------------- /** * Builder for {@link MsearchTemplateRequest}. */ public static class Builder extends RequestBase.AbstractBuilder implements ObjectBuilder { @Nullable private Boolean ccsMinimizeRoundtrips; @Nullable private List index; @Nullable private Long maxConcurrentSearches; @Nullable private SearchType searchType; private List searchTemplates; /** * 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; } /** * Comma-separated list of data streams, indices, and aliases to search. * Supports wildcards (*). To search all data streams and indices, * omit this parameter or use *. *

* 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 (*). To search all data streams and indices, * omit this parameter or use *. *

* 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; } /** * Maximum number of concurrent searches the API can run. *

* API name: {@code max_concurrent_searches} */ public final Builder maxConcurrentSearches(@Nullable Long value) { this.maxConcurrentSearches = value; return this; } /** * The type of the search operation. Available options: * query_then_fetch, dfs_query_then_fetch. *

* API name: {@code search_type} */ public final Builder searchType(@Nullable SearchType value) { this.searchType = value; return this; } /** * Required - Request body. *

* Adds all elements of list to searchTemplates. */ public final Builder searchTemplates(List list) { this.searchTemplates = _listAddAll(this.searchTemplates, list); return this; } /** * Required - Request body. *

* Adds one or more values to searchTemplates. */ public final Builder searchTemplates(RequestItem value, RequestItem... values) { this.searchTemplates = _listAdd(this.searchTemplates, value, values); return this; } /** * Required - Request body. *

* Adds a value to searchTemplates using a builder lambda. */ public final Builder searchTemplates(Function> fn) { return searchTemplates(fn.apply(new RequestItem.Builder()).build()); } @Override protected Builder self() { return this; } /** * Builds a {@link MsearchTemplateRequest}. * * @throws NullPointerException * if some of the required fields are null. */ public MsearchTemplateRequest build() { _checkSingleUse(); return new MsearchTemplateRequest(this); } } // --------------------------------------------------------------------------------------------- /** * Endpoint "{@code msearch_template}". */ public static final SimpleEndpoint _ENDPOINT = new SimpleEndpoint<>( "es/msearch_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("/_msearch"); 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("/_msearch"); 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 (request.maxConcurrentSearches != null) { params.put("max_concurrent_searches", String.valueOf(request.maxConcurrentSearches)); } if (request.searchType != null) { params.put("search_type", request.searchType.jsonValue()); } if (request.ccsMinimizeRoundtrips != null) { params.put("ccs_minimize_roundtrips", String.valueOf(request.ccsMinimizeRoundtrips)); } return params; }, SimpleEndpoint.emptyMap(), true, MsearchTemplateResponse._DESERIALIZER); /** * Create an "{@code msearch_template}" endpoint. */ public static Endpoint, ErrorResponse> createMsearchTemplateEndpoint( JsonpDeserializer tDocumentDeserializer) { return _ENDPOINT.withResponseDeserializer( MsearchTemplateResponse.createMsearchTemplateResponseDeserializer(tDocumentDeserializer)); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy