co.elastic.clients.elasticsearch.sql.TranslateResponse 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.sql;
import co.elastic.clients.elasticsearch._types.SortOptions;
import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
import co.elastic.clients.elasticsearch._types.query_dsl.FieldAndFormat;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import co.elastic.clients.elasticsearch.core.search.SourceConfig;
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.JsonpUtils;
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.Long;
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;
//----------------------------------------------------------------
// 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: sql.translate.Response
/**
*
* @see API
* specification
*/
@JsonpDeserializable
public class TranslateResponse implements JsonpSerializable {
private final Map aggregations;
@Nullable
private final Long size;
@Nullable
private final SourceConfig source;
private final List fields;
@Nullable
private final Query query;
private final List sort;
// ---------------------------------------------------------------------------------------------
private TranslateResponse(Builder builder) {
this.aggregations = ApiTypeHelper.unmodifiable(builder.aggregations);
this.size = builder.size;
this.source = builder.source;
this.fields = ApiTypeHelper.unmodifiable(builder.fields);
this.query = builder.query;
this.sort = ApiTypeHelper.unmodifiable(builder.sort);
}
public static TranslateResponse of(Function> fn) {
return fn.apply(new Builder()).build();
}
/**
* API name: {@code aggregations}
*/
public final Map aggregations() {
return this.aggregations;
}
/**
* API name: {@code size}
*/
@Nullable
public final Long size() {
return this.size;
}
/**
* API name: {@code _source}
*/
@Nullable
public final SourceConfig source() {
return this.source;
}
/**
* API name: {@code fields}
*/
public final List fields() {
return this.fields;
}
/**
* API name: {@code query}
*/
@Nullable
public final Query query() {
return this.query;
}
/**
* API name: {@code sort}
*/
public final List sort() {
return this.sort;
}
/**
* 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.size != null) {
generator.writeKey("size");
generator.write(this.size);
}
if (this.source != null) {
generator.writeKey("_source");
this.source.serialize(generator, mapper);
}
if (ApiTypeHelper.isDefined(this.fields)) {
generator.writeKey("fields");
generator.writeStartArray();
for (FieldAndFormat item0 : this.fields) {
item0.serialize(generator, mapper);
}
generator.writeEnd();
}
if (this.query != null) {
generator.writeKey("query");
this.query.serialize(generator, mapper);
}
if (ApiTypeHelper.isDefined(this.sort)) {
generator.writeKey("sort");
generator.writeStartArray();
for (SortOptions item0 : this.sort) {
item0.serialize(generator, mapper);
}
generator.writeEnd();
}
}
@Override
public String toString() {
return JsonpUtils.toString(this);
}
// ---------------------------------------------------------------------------------------------
/**
* Builder for {@link TranslateResponse}.
*/
public static class Builder extends WithJsonObjectBuilderBase implements ObjectBuilder {
@Nullable
private Map aggregations;
@Nullable
private Long size;
@Nullable
private SourceConfig source;
@Nullable
private List fields;
@Nullable
private Query query;
@Nullable
private List sort;
/**
* 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 size}
*/
public final Builder size(@Nullable Long value) {
this.size = value;
return this;
}
/**
* API name: {@code _source}
*/
public final Builder source(@Nullable SourceConfig value) {
this.source = value;
return this;
}
/**
* API name: {@code _source}
*/
public final Builder source(Function> fn) {
return this.source(fn.apply(new SourceConfig.Builder()).build());
}
/**
* API name: {@code fields}
*
* Adds all elements of list
to fields
.
*/
public final Builder fields(List list) {
this.fields = _listAddAll(this.fields, list);
return this;
}
/**
* API name: {@code fields}
*
* Adds one or more values to fields
.
*/
public final Builder fields(FieldAndFormat value, FieldAndFormat... values) {
this.fields = _listAdd(this.fields, value, values);
return this;
}
/**
* API name: {@code fields}
*
* Adds a value to fields
using a builder lambda.
*/
public final Builder fields(Function> fn) {
return fields(fn.apply(new FieldAndFormat.Builder()).build());
}
/**
* API name: {@code query}
*/
public final Builder query(@Nullable Query value) {
this.query = value;
return this;
}
/**
* API name: {@code query}
*/
public final Builder query(Function> fn) {
return this.query(fn.apply(new Query.Builder()).build());
}
/**
* API name: {@code sort}
*
* Adds all elements of list
to sort
.
*/
public final Builder sort(List list) {
this.sort = _listAddAll(this.sort, list);
return this;
}
/**
* API name: {@code sort}
*
* Adds one or more values to sort
.
*/
public final Builder sort(SortOptions value, SortOptions... values) {
this.sort = _listAdd(this.sort, value, values);
return this;
}
/**
* API name: {@code sort}
*
* Adds a value to sort
using a builder lambda.
*/
public final Builder sort(Function> fn) {
return sort(fn.apply(new SortOptions.Builder()).build());
}
@Override
protected Builder self() {
return this;
}
/**
* Builds a {@link TranslateResponse}.
*
* @throws NullPointerException
* if some of the required fields are null.
*/
public TranslateResponse build() {
_checkSingleUse();
return new TranslateResponse(this);
}
}
// ---------------------------------------------------------------------------------------------
/**
* Json deserializer for {@link TranslateResponse}
*/
public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer
.lazy(Builder::new, TranslateResponse::setupTranslateResponseDeserializer);
protected static void setupTranslateResponseDeserializer(ObjectDeserializer op) {
op.add(Builder::aggregations, JsonpDeserializer.stringMapDeserializer(Aggregation._DESERIALIZER),
"aggregations");
op.add(Builder::size, JsonpDeserializer.longDeserializer(), "size");
op.add(Builder::source, SourceConfig._DESERIALIZER, "_source");
op.add(Builder::fields, JsonpDeserializer.arrayDeserializer(FieldAndFormat._DESERIALIZER), "fields");
op.add(Builder::query, Query._DESERIALIZER, "query");
op.add(Builder::sort, JsonpDeserializer.arrayDeserializer(SortOptions._DESERIALIZER), "sort");
}
}