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

co.elastic.clients.elasticsearch.ml.Datafeed Maven / Gradle / Ivy

There is a newer version: 8.17.0
Show 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.
 */

//----------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------

package co.elastic.clients.elasticsearch.ml;

import co.elastic.clients.elasticsearch._types.IndicesOptions;
import co.elastic.clients.elasticsearch._types.ScriptField;
import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
import co.elastic.clients.elasticsearch._types.mapping.RuntimeField;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
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.util.ApiTypeHelper;
import co.elastic.clients.util.DateTime;
import co.elastic.clients.util.ObjectBuilder;
import co.elastic.clients.util.WithJsonObjectBuilderBase;
import jakarta.json.stream.JsonGenerator;
import java.lang.Integer;
import java.lang.String;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;

// typedef: ml._types.Datafeed

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

	@Nullable
	private final ChunkingConfig chunkingConfig;

	private final String datafeedId;

	@Nullable
	private final DateTime frequency;

	private final List indices;

	private final List indexes;

	private final String jobId;

	@Nullable
	private final Integer maxEmptySearches;

	private final Query query;

	@Nullable
	private final DateTime queryDelay;

	private final Map scriptFields;

	@Nullable
	private final Integer scrollSize;

	private final DelayedDataCheckConfig delayedDataCheckConfig;

	private final Map> runtimeMappings;

	@Nullable
	private final IndicesOptions indicesOptions;

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

	private Datafeed(Builder builder) {

		this.aggregations = ApiTypeHelper.unmodifiable(builder.aggregations);
		this.chunkingConfig = builder.chunkingConfig;
		this.datafeedId = ApiTypeHelper.requireNonNull(builder.datafeedId, this, "datafeedId");
		this.frequency = builder.frequency;
		this.indices = ApiTypeHelper.unmodifiableRequired(builder.indices, this, "indices");
		this.indexes = ApiTypeHelper.unmodifiable(builder.indexes);
		this.jobId = ApiTypeHelper.requireNonNull(builder.jobId, this, "jobId");
		this.maxEmptySearches = builder.maxEmptySearches;
		this.query = ApiTypeHelper.requireNonNull(builder.query, this, "query");
		this.queryDelay = builder.queryDelay;
		this.scriptFields = ApiTypeHelper.unmodifiable(builder.scriptFields);
		this.scrollSize = builder.scrollSize;
		this.delayedDataCheckConfig = ApiTypeHelper.requireNonNull(builder.delayedDataCheckConfig, this,
				"delayedDataCheckConfig");
		this.runtimeMappings = ApiTypeHelper.unmodifiable(builder.runtimeMappings);
		this.indicesOptions = builder.indicesOptions;

	}

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

	/**
	 * API name: {@code aggregations}
	 */
	public final Map aggregations() {
		return this.aggregations;
	}

	/**
	 * API name: {@code chunking_config}
	 */
	@Nullable
	public final ChunkingConfig chunkingConfig() {
		return this.chunkingConfig;
	}

	/**
	 * Required - API name: {@code datafeed_id}
	 */
	public final String datafeedId() {
		return this.datafeedId;
	}

	/**
	 * API name: {@code frequency}
	 */
	@Nullable
	public final DateTime frequency() {
		return this.frequency;
	}

	/**
	 * Required - API name: {@code indices}
	 */
	public final List indices() {
		return this.indices;
	}

	/**
	 * API name: {@code indexes}
	 */
	public final List indexes() {
		return this.indexes;
	}

	/**
	 * Required - API name: {@code job_id}
	 */
	public final String jobId() {
		return this.jobId;
	}

	/**
	 * API name: {@code max_empty_searches}
	 */
	@Nullable
	public final Integer maxEmptySearches() {
		return this.maxEmptySearches;
	}

	/**
	 * Required - API name: {@code query}
	 */
	public final Query query() {
		return this.query;
	}

	/**
	 * API name: {@code query_delay}
	 */
	@Nullable
	public final DateTime queryDelay() {
		return this.queryDelay;
	}

	/**
	 * API name: {@code script_fields}
	 */
	public final Map scriptFields() {
		return this.scriptFields;
	}

	/**
	 * API name: {@code scroll_size}
	 */
	@Nullable
	public final Integer scrollSize() {
		return this.scrollSize;
	}

	/**
	 * Required - API name: {@code delayed_data_check_config}
	 */
	public final DelayedDataCheckConfig delayedDataCheckConfig() {
		return this.delayedDataCheckConfig;
	}

	/**
	 * API name: {@code runtime_mappings}
	 */
	public final Map> runtimeMappings() {
		return this.runtimeMappings;
	}

	/**
	 * API name: {@code indices_options}
	 */
	@Nullable
	public final IndicesOptions indicesOptions() {
		return this.indicesOptions;
	}

	/**
	 * 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");
			generator.writeStartObject();
			for (Map.Entry item0 : this.aggregations.entrySet()) {
				generator.writeKey(item0.getKey());
				item0.getValue().serialize(generator, mapper);

			}
			generator.writeEnd();

		}
		if (this.chunkingConfig != null) {
			generator.writeKey("chunking_config");
			this.chunkingConfig.serialize(generator, mapper);

		}
		generator.writeKey("datafeed_id");
		generator.write(this.datafeedId);

		if (this.frequency != null) {
			generator.writeKey("frequency");
			this.frequency.serialize(generator, mapper);
		}
		if (ApiTypeHelper.isDefined(this.indices)) {
			generator.writeKey("indices");
			generator.writeStartArray();
			for (String item0 : this.indices) {
				generator.write(item0);

			}
			generator.writeEnd();

		}
		if (ApiTypeHelper.isDefined(this.indexes)) {
			generator.writeKey("indexes");
			generator.writeStartArray();
			for (String item0 : this.indexes) {
				generator.write(item0);

			}
			generator.writeEnd();

		}
		generator.writeKey("job_id");
		generator.write(this.jobId);

		if (this.maxEmptySearches != null) {
			generator.writeKey("max_empty_searches");
			generator.write(this.maxEmptySearches);

		}
		generator.writeKey("query");
		this.query.serialize(generator, mapper);

		if (this.queryDelay != null) {
			generator.writeKey("query_delay");
			this.queryDelay.serialize(generator, mapper);
		}
		if (ApiTypeHelper.isDefined(this.scriptFields)) {
			generator.writeKey("script_fields");
			generator.writeStartObject();
			for (Map.Entry item0 : this.scriptFields.entrySet()) {
				generator.writeKey(item0.getKey());
				item0.getValue().serialize(generator, mapper);

			}
			generator.writeEnd();

		}
		if (this.scrollSize != null) {
			generator.writeKey("scroll_size");
			generator.write(this.scrollSize);

		}
		generator.writeKey("delayed_data_check_config");
		this.delayedDataCheckConfig.serialize(generator, mapper);

		if (ApiTypeHelper.isDefined(this.runtimeMappings)) {
			generator.writeKey("runtime_mappings");
			generator.writeStartObject();
			for (Map.Entry> item0 : this.runtimeMappings.entrySet()) {
				generator.writeKey(item0.getKey());
				generator.writeStartArray();
				if (item0.getValue() != null) {
					for (RuntimeField item1 : item0.getValue()) {
						item1.serialize(generator, mapper);

					}
				}
				generator.writeEnd();

			}
			generator.writeEnd();

		}
		if (this.indicesOptions != null) {
			generator.writeKey("indices_options");
			this.indicesOptions.serialize(generator, mapper);

		}

	}

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

	/**
	 * Builder for {@link Datafeed}.
	 */

	public static class Builder extends WithJsonObjectBuilderBase implements ObjectBuilder {
		@Nullable
		private Map aggregations;

		@Nullable
		private ChunkingConfig chunkingConfig;

		private String datafeedId;

		@Nullable
		private DateTime frequency;

		private List indices;

		@Nullable
		private List indexes;

		private String jobId;

		@Nullable
		private Integer maxEmptySearches;

		private Query query;

		@Nullable
		private DateTime queryDelay;

		@Nullable
		private Map scriptFields;

		@Nullable
		private Integer scrollSize;

		private DelayedDataCheckConfig delayedDataCheckConfig;

		@Nullable
		private Map> runtimeMappings;

		@Nullable
		private IndicesOptions indicesOptions;

		/**
		 * 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; } /** * API name: {@code aggregations} *

* Adds an entry to aggregations. */ public final Builder aggregations(String key, Aggregation value) { this.aggregations = _mapPut(this.aggregations, key, value); return this; } /** * 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 Aggregation.Builder()).build()); } /** * API name: {@code chunking_config} */ public final Builder chunkingConfig(@Nullable ChunkingConfig value) { this.chunkingConfig = value; return this; } /** * API name: {@code chunking_config} */ public final Builder chunkingConfig(Function> fn) { return this.chunkingConfig(fn.apply(new ChunkingConfig.Builder()).build()); } /** * Required - API name: {@code datafeed_id} */ public final Builder datafeedId(String value) { this.datafeedId = value; return this; } /** * API name: {@code frequency} */ public final Builder frequency(@Nullable DateTime value) { this.frequency = value; return this; } /** * Required - API name: {@code indices} *

* Adds all elements of list to indices. */ public final Builder indices(List list) { this.indices = _listAddAll(this.indices, list); return this; } /** * Required - API name: {@code indices} *

* Adds one or more values to indices. */ public final Builder indices(String value, String... values) { this.indices = _listAdd(this.indices, value, values); return this; } /** * API name: {@code indexes} *

* Adds all elements of list to indexes. */ public final Builder indexes(List list) { this.indexes = _listAddAll(this.indexes, list); return this; } /** * API name: {@code indexes} *

* Adds one or more values to indexes. */ public final Builder indexes(String value, String... values) { this.indexes = _listAdd(this.indexes, value, values); return this; } /** * Required - API name: {@code job_id} */ public final Builder jobId(String value) { this.jobId = value; return this; } /** * API name: {@code max_empty_searches} */ public final Builder maxEmptySearches(@Nullable Integer value) { this.maxEmptySearches = value; return this; } /** * Required - API name: {@code query} */ public final Builder query(Query value) { this.query = value; return this; } /** * Required - API name: {@code query} */ public final Builder query(Function> fn) { return this.query(fn.apply(new Query.Builder()).build()); } /** * API name: {@code query_delay} */ public final Builder queryDelay(@Nullable DateTime value) { this.queryDelay = value; return this; } /** * API name: {@code script_fields} *

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

* Adds an entry to scriptFields. */ public final Builder scriptFields(String key, ScriptField value) { this.scriptFields = _mapPut(this.scriptFields, key, value); return this; } /** * API name: {@code script_fields} *

* Adds an entry to scriptFields using a builder lambda. */ public final Builder scriptFields(String key, Function> fn) { return scriptFields(key, fn.apply(new ScriptField.Builder()).build()); } /** * API name: {@code scroll_size} */ public final Builder scrollSize(@Nullable Integer value) { this.scrollSize = value; return this; } /** * Required - API name: {@code delayed_data_check_config} */ public final Builder delayedDataCheckConfig(DelayedDataCheckConfig value) { this.delayedDataCheckConfig = value; return this; } /** * Required - API name: {@code delayed_data_check_config} */ public final Builder delayedDataCheckConfig( Function> fn) { return this.delayedDataCheckConfig(fn.apply(new DelayedDataCheckConfig.Builder()).build()); } /** * API name: {@code runtime_mappings} *

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

* Adds an entry to runtimeMappings. */ public final Builder runtimeMappings(String key, List value) { this.runtimeMappings = _mapPut(this.runtimeMappings, key, value); return this; } /** * API name: {@code indices_options} */ public final Builder indicesOptions(@Nullable IndicesOptions value) { this.indicesOptions = value; return this; } /** * API name: {@code indices_options} */ public final Builder indicesOptions(Function> fn) { return this.indicesOptions(fn.apply(new IndicesOptions.Builder()).build()); } @Override protected Builder self() { return this; } /** * Builds a {@link Datafeed}. * * @throws NullPointerException * if some of the required fields are null. */ public Datafeed build() { _checkSingleUse(); return new Datafeed(this); } } // --------------------------------------------------------------------------------------------- /** * Json deserializer for {@link Datafeed} */ public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy(Builder::new, Datafeed::setupDatafeedDeserializer); protected static void setupDatafeedDeserializer(ObjectDeserializer op) { op.add(Builder::aggregations, JsonpDeserializer.stringMapDeserializer(Aggregation._DESERIALIZER), "aggregations", "aggs"); op.add(Builder::chunkingConfig, ChunkingConfig._DESERIALIZER, "chunking_config"); op.add(Builder::datafeedId, JsonpDeserializer.stringDeserializer(), "datafeed_id"); op.add(Builder::frequency, DateTime._DESERIALIZER, "frequency"); op.add(Builder::indices, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "indices"); op.add(Builder::indexes, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "indexes"); op.add(Builder::jobId, JsonpDeserializer.stringDeserializer(), "job_id"); op.add(Builder::maxEmptySearches, JsonpDeserializer.integerDeserializer(), "max_empty_searches"); op.add(Builder::query, Query._DESERIALIZER, "query"); op.add(Builder::queryDelay, DateTime._DESERIALIZER, "query_delay"); op.add(Builder::scriptFields, JsonpDeserializer.stringMapDeserializer(ScriptField._DESERIALIZER), "script_fields"); op.add(Builder::scrollSize, JsonpDeserializer.integerDeserializer(), "scroll_size"); op.add(Builder::delayedDataCheckConfig, DelayedDataCheckConfig._DESERIALIZER, "delayed_data_check_config"); op.add(Builder::runtimeMappings, JsonpDeserializer.stringMapDeserializer( JsonpDeserializer.arrayDeserializer(RuntimeField._DESERIALIZER)), "runtime_mappings"); op.add(Builder::indicesOptions, IndicesOptions._DESERIALIZER, "indices_options"); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy