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

co.elastic.clients.elasticsearch.async_search.AsyncSearch 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.
 */

package co.elastic.clients.elasticsearch.async_search;

import co.elastic.clients.elasticsearch._types.ClusterStatistics;
import co.elastic.clients.elasticsearch._types.ShardStatistics;
import co.elastic.clients.elasticsearch._types.aggregations.Aggregate;
import co.elastic.clients.elasticsearch.core.search.HitsMetadata;
import co.elastic.clients.elasticsearch.core.search.Profile;
import co.elastic.clients.elasticsearch.core.search.Suggestion;
import co.elastic.clients.json.ExternallyTaggedUnion;
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.JsonpSerializer;
import co.elastic.clients.json.JsonpUtils;
import co.elastic.clients.json.NamedDeserializer;
import co.elastic.clients.json.ObjectBuilderDeserializer;
import co.elastic.clients.json.ObjectDeserializer;
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.Double;
import java.lang.Long;
import java.lang.String;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
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: async_search._types.AsyncSearch

/**
 *
 * @see API
 *      specification
 */
@JsonpDeserializable
public class AsyncSearch implements JsonpSerializable {
	private final Map aggregations;

	@Nullable
	private final ClusterStatistics clusters;

	private final Map fields;

	private final HitsMetadata hits;

	@Nullable
	private final Double maxScore;

	@Nullable
	private final Long numReducePhases;

	@Nullable
	private final Profile profile;

	@Nullable
	private final String pitId;

	@Nullable
	private final String scrollId;

	private final ShardStatistics shards;

	private final Map>> suggest;

	@Nullable
	private final Boolean terminatedEarly;

	private final boolean timedOut;

	private final long took;

	@Nullable
	private final JsonpSerializer tDocumentSerializer;

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

	private AsyncSearch(Builder builder) {

		this.aggregations = ApiTypeHelper.unmodifiable(builder.aggregations);
		this.clusters = builder.clusters;
		this.fields = ApiTypeHelper.unmodifiable(builder.fields);
		this.hits = ApiTypeHelper.requireNonNull(builder.hits, this, "hits");
		this.maxScore = builder.maxScore;
		this.numReducePhases = builder.numReducePhases;
		this.profile = builder.profile;
		this.pitId = builder.pitId;
		this.scrollId = builder.scrollId;
		this.shards = ApiTypeHelper.requireNonNull(builder.shards, this, "shards");
		this.suggest = ApiTypeHelper.unmodifiable(builder.suggest);
		this.terminatedEarly = builder.terminatedEarly;
		this.timedOut = ApiTypeHelper.requireNonNull(builder.timedOut, this, "timedOut");
		this.took = ApiTypeHelper.requireNonNull(builder.took, this, "took");
		this.tDocumentSerializer = builder.tDocumentSerializer;

	}

	public static  AsyncSearch of(
			Function, ObjectBuilder>> fn) {
		return fn.apply(new Builder<>()).build();
	}

	/**
	 * Partial aggregations results, coming from the shards that have already
	 * completed the execution of the query.
	 * 

* API name: {@code aggregations} */ public final Map aggregations() { return this.aggregations; } /** * API name: {@code _clusters} */ @Nullable public final ClusterStatistics clusters() { return this.clusters; } /** * API name: {@code fields} */ public final Map fields() { return this.fields; } /** * Required - API name: {@code hits} */ public final HitsMetadata hits() { return this.hits; } /** * API name: {@code max_score} */ @Nullable public final Double maxScore() { return this.maxScore; } /** * Indicates how many reductions of the results have been performed. If this * number increases compared to the last retrieved results for a get asynch * search request, you can expect additional results included in the search * response. *

* API name: {@code num_reduce_phases} */ @Nullable public final Long numReducePhases() { return this.numReducePhases; } /** * API name: {@code profile} */ @Nullable public final Profile profile() { return this.profile; } /** * API name: {@code pit_id} */ @Nullable public final String pitId() { return this.pitId; } /** * API name: {@code _scroll_id} */ @Nullable public final String scrollId() { return this.scrollId; } /** * Required - Indicates how many shards have run the query. Note that in order * for shard results to be included in the search response, they need to be * reduced first. *

* API name: {@code _shards} */ public final ShardStatistics shards() { return this.shards; } /** * API name: {@code suggest} */ public final Map>> suggest() { return this.suggest; } /** * API name: {@code terminated_early} */ @Nullable public final Boolean terminatedEarly() { return this.terminatedEarly; } /** * Required - API name: {@code timed_out} */ public final boolean timedOut() { return this.timedOut; } /** * Required - API name: {@code took} */ public final long took() { return this.took; } /** * 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.aggregations)) { generator.writeKey("aggregations"); ExternallyTaggedUnion.serializeTypedKeys(this.aggregations, generator, mapper); } if (this.clusters != null) { generator.writeKey("_clusters"); this.clusters.serialize(generator, mapper); } if (ApiTypeHelper.isDefined(this.fields)) { generator.writeKey("fields"); generator.writeStartObject(); for (Map.Entry item0 : this.fields.entrySet()) { generator.writeKey(item0.getKey()); item0.getValue().serialize(generator, mapper); } generator.writeEnd(); } generator.writeKey("hits"); this.hits.serialize(generator, mapper); if (this.maxScore != null) { generator.writeKey("max_score"); generator.write(this.maxScore); } if (this.numReducePhases != null) { generator.writeKey("num_reduce_phases"); generator.write(this.numReducePhases); } if (this.profile != null) { generator.writeKey("profile"); this.profile.serialize(generator, mapper); } if (this.pitId != null) { generator.writeKey("pit_id"); generator.write(this.pitId); } if (this.scrollId != null) { generator.writeKey("_scroll_id"); generator.write(this.scrollId); } generator.writeKey("_shards"); this.shards.serialize(generator, mapper); if (ApiTypeHelper.isDefined(this.suggest)) { generator.writeKey("suggest"); ExternallyTaggedUnion.serializeTypedKeysArray(this.suggest, generator, mapper); } if (this.terminatedEarly != null) { generator.writeKey("terminated_early"); generator.write(this.terminatedEarly); } generator.writeKey("timed_out"); generator.write(this.timedOut); generator.writeKey("took"); generator.write(this.took); } @Override public String toString() { return JsonpUtils.toString(this); } // --------------------------------------------------------------------------------------------- /** * Builder for {@link AsyncSearch}. */ public static class Builder extends WithJsonObjectBuilderBase> implements ObjectBuilder> { @Nullable private Map aggregations; @Nullable private ClusterStatistics clusters; @Nullable private Map fields; private HitsMetadata hits; @Nullable private Double maxScore; @Nullable private Long numReducePhases; @Nullable private Profile profile; @Nullable private String pitId; @Nullable private String scrollId; private ShardStatistics shards; @Nullable private Map>> suggest; @Nullable private Boolean terminatedEarly; private Boolean timedOut; private Long took; @Nullable private JsonpSerializer tDocumentSerializer; /** * Partial aggregations results, coming from the shards that have already * completed the execution of the query. *

* API name: {@code aggregations} *

* Adds all entries of map to aggregations. */ public final Builder aggregations(Map map) { this.aggregations = _mapPutAll(this.aggregations, map); return this; } /** * Partial aggregations results, coming from the shards that have already * completed the execution of the query. *

* API name: {@code aggregations} *

* Adds an entry to aggregations. */ public final Builder aggregations(String key, Aggregate value) { this.aggregations = _mapPut(this.aggregations, key, value); return this; } /** * Partial aggregations results, coming from the shards that have already * completed the execution of the query. *

* API name: {@code aggregations} *

* Adds an entry to aggregations using a builder lambda. */ public final Builder aggregations(String key, Function> fn) { return aggregations(key, fn.apply(new Aggregate.Builder()).build()); } /** * API name: {@code _clusters} */ public final Builder clusters(@Nullable ClusterStatistics value) { this.clusters = value; return this; } /** * API name: {@code _clusters} */ public final Builder clusters( Function> fn) { return this.clusters(fn.apply(new ClusterStatistics.Builder()).build()); } /** * API name: {@code fields} *

* Adds all entries of map to fields. */ public final Builder fields(Map map) { this.fields = _mapPutAll(this.fields, map); return this; } /** * API name: {@code fields} *

* Adds an entry to fields. */ public final Builder fields(String key, JsonData value) { this.fields = _mapPut(this.fields, key, value); return this; } /** * Required - API name: {@code hits} */ public final Builder hits(HitsMetadata value) { this.hits = value; return this; } /** * Required - API name: {@code hits} */ public final Builder hits( Function, ObjectBuilder>> fn) { return this.hits(fn.apply(new HitsMetadata.Builder()).build()); } /** * API name: {@code max_score} */ public final Builder maxScore(@Nullable Double value) { this.maxScore = value; return this; } /** * Indicates how many reductions of the results have been performed. If this * number increases compared to the last retrieved results for a get asynch * search request, you can expect additional results included in the search * response. *

* API name: {@code num_reduce_phases} */ public final Builder numReducePhases(@Nullable Long value) { this.numReducePhases = value; return this; } /** * API name: {@code profile} */ public final Builder profile(@Nullable Profile value) { this.profile = value; return this; } /** * API name: {@code profile} */ public final Builder profile(Function> fn) { return this.profile(fn.apply(new Profile.Builder()).build()); } /** * API name: {@code pit_id} */ public final Builder pitId(@Nullable String value) { this.pitId = value; return this; } /** * API name: {@code _scroll_id} */ public final Builder scrollId(@Nullable String value) { this.scrollId = value; return this; } /** * Required - Indicates how many shards have run the query. Note that in order * for shard results to be included in the search response, they need to be * reduced first. *

* API name: {@code _shards} */ public final Builder shards(ShardStatistics value) { this.shards = value; return this; } /** * Required - Indicates how many shards have run the query. Note that in order * for shard results to be included in the search response, they need to be * reduced first. *

* API name: {@code _shards} */ public final Builder shards(Function> fn) { return this.shards(fn.apply(new ShardStatistics.Builder()).build()); } /** * API name: {@code suggest} *

* Adds all entries of map to suggest. */ public final Builder suggest(Map>> map) { this.suggest = _mapPutAll(this.suggest, map); return this; } /** * API name: {@code suggest} *

* Adds an entry to suggest. */ public final Builder suggest(String key, List> value) { this.suggest = _mapPut(this.suggest, key, value); return this; } /** * API name: {@code terminated_early} */ public final Builder terminatedEarly(@Nullable Boolean value) { this.terminatedEarly = value; return this; } /** * Required - API name: {@code timed_out} */ public final Builder timedOut(boolean value) { this.timedOut = value; return this; } /** * Required - API name: {@code took} */ public final Builder took(long value) { this.took = value; return this; } /** * Serializer for TDocument. If not set, an attempt will be made to find a * serializer from the JSON context. */ public final Builder tDocumentSerializer(@Nullable JsonpSerializer value) { this.tDocumentSerializer = value; return this; } @Override protected Builder self() { return this; } /** * Builds a {@link AsyncSearch}. * * @throws NullPointerException * if some of the required fields are null. */ public AsyncSearch build() { _checkSingleUse(); return new AsyncSearch(this); } } // --------------------------------------------------------------------------------------------- /** * Create a JSON deserializer for AsyncSearch */ public static JsonpDeserializer> createAsyncSearchDeserializer( JsonpDeserializer tDocumentDeserializer) { return ObjectBuilderDeserializer.createForObject((Supplier>) Builder::new, op -> AsyncSearch.setupAsyncSearchDeserializer(op, tDocumentDeserializer)); }; /** * Json deserializer for {@link AsyncSearch} based on named deserializers * provided by the calling {@code JsonMapper}. */ public static final JsonpDeserializer> _DESERIALIZER = JsonpDeserializer .lazy(() -> createAsyncSearchDeserializer(new NamedDeserializer<>( "co.elastic.clients:Deserializer:async_search._types.AsyncSearch.TDocument"))); protected static void setupAsyncSearchDeserializer( ObjectDeserializer> op, JsonpDeserializer tDocumentDeserializer) { op.add(Builder::aggregations, Aggregate._TYPED_KEYS_DESERIALIZER, "aggregations"); op.add(Builder::clusters, ClusterStatistics._DESERIALIZER, "_clusters"); op.add(Builder::fields, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "fields"); op.add(Builder::hits, HitsMetadata.createHitsMetadataDeserializer(tDocumentDeserializer), "hits"); op.add(Builder::maxScore, JsonpDeserializer.doubleDeserializer(), "max_score"); op.add(Builder::numReducePhases, JsonpDeserializer.longDeserializer(), "num_reduce_phases"); op.add(Builder::profile, Profile._DESERIALIZER, "profile"); op.add(Builder::pitId, JsonpDeserializer.stringDeserializer(), "pit_id"); op.add(Builder::scrollId, JsonpDeserializer.stringDeserializer(), "_scroll_id"); op.add(Builder::shards, ShardStatistics._DESERIALIZER, "_shards"); op.add(Builder::suggest, ExternallyTaggedUnion.>arrayMapDeserializer( Suggestion.createSuggestionDeserializer(tDocumentDeserializer)), "suggest"); op.add(Builder::terminatedEarly, JsonpDeserializer.booleanDeserializer(), "terminated_early"); op.add(Builder::timedOut, JsonpDeserializer.booleanDeserializer(), "timed_out"); op.add(Builder::took, JsonpDeserializer.longDeserializer(), "took"); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy