co.elastic.clients.elasticsearch.rollup.RollupSearchRequest Maven / Gradle / Ivy
Show all versions of elasticsearch-java Show documentation
/*
* 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.rollup;
import co.elastic.clients.elasticsearch._types.ErrorResponse;
import co.elastic.clients.elasticsearch._types.RequestBase;
import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
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.transport.Endpoint;
import co.elastic.clients.transport.endpoints.SimpleEndpoint;
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.Integer;
import java.lang.String;
import java.util.Collections;
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;
// typedef: rollup.rollup_search.Request
/**
* Enables searching rolled-up data using the standard query DSL.
*
* @see API
* specification
*/
@JsonpDeserializable
public class RollupSearchRequest extends RequestBase implements JsonpSerializable {
private final Map aggregations;
private final List index;
@Nullable
private final Query query;
@Nullable
private final Integer size;
// ---------------------------------------------------------------------------------------------
private RollupSearchRequest(Builder builder) {
this.aggregations = ApiTypeHelper.unmodifiable(builder.aggregations);
this.index = ApiTypeHelper.unmodifiableRequired(builder.index, this, "index");
this.query = builder.query;
this.size = builder.size;
}
public static RollupSearchRequest of(Function> fn) {
return fn.apply(new Builder()).build();
}
/**
* API name: {@code aggregations}
*/
public final Map aggregations() {
return this.aggregations;
}
/**
* Required - The indices or index-pattern(s) (containing rollup or regular
* data) that should be searched
*
* API name: {@code index}
*/
public final List index() {
return this.index;
}
/**
* API name: {@code query}
*/
@Nullable
public final Query query() {
return this.query;
}
/**
* Must be zero if set, as rollups work on pre-aggregated data
*
* API name: {@code size}
*/
@Nullable
public final Integer size() {
return this.size;
}
/**
* 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.query != null) {
generator.writeKey("query");
this.query.serialize(generator, mapper);
}
if (this.size != null) {
generator.writeKey("size");
generator.write(this.size);
}
}
// ---------------------------------------------------------------------------------------------
/**
* Builder for {@link RollupSearchRequest}.
*/
public static class Builder extends WithJsonObjectBuilderBase
implements
ObjectBuilder {
@Nullable
private Map aggregations;
private List index;
@Nullable
private Query query;
@Nullable
private Integer size;
/**
* 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());
}
/**
* Required - The indices or index-pattern(s) (containing rollup or regular
* data) that should be searched
*
* 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;
}
/**
* Required - The indices or index-pattern(s) (containing rollup or regular
* data) that should be searched
*
* 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;
}
/**
* 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());
}
/**
* Must be zero if set, as rollups work on pre-aggregated data
*
* API name: {@code size}
*/
public final Builder size(@Nullable Integer value) {
this.size = value;
return this;
}
@Override
protected Builder self() {
return this;
}
/**
* Builds a {@link RollupSearchRequest}.
*
* @throws NullPointerException
* if some of the required fields are null.
*/
public RollupSearchRequest build() {
_checkSingleUse();
return new RollupSearchRequest(this);
}
}
// ---------------------------------------------------------------------------------------------
/**
* Json deserializer for {@link RollupSearchRequest}
*/
public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer
.lazy(Builder::new, RollupSearchRequest::setupRollupSearchRequestDeserializer);
protected static void setupRollupSearchRequestDeserializer(ObjectDeserializer op) {
op.add(Builder::aggregations, JsonpDeserializer.stringMapDeserializer(Aggregation._DESERIALIZER),
"aggregations", "aggs");
op.add(Builder::query, Query._DESERIALIZER, "query");
op.add(Builder::size, JsonpDeserializer.integerDeserializer(), "size");
}
// ---------------------------------------------------------------------------------------------
/**
* Endpoint "{@code rollup.rollup_search}".
*/
public static final SimpleEndpoint _ENDPOINT = new SimpleEndpoint<>(
"es/rollup.rollup_search",
// Request method
request -> {
return "POST";
},
// Request path
request -> {
final int _index = 1 << 0;
int propsSet = 0;
propsSet |= _index;
if (propsSet == (_index)) {
StringBuilder buf = new StringBuilder();
buf.append("/");
SimpleEndpoint.pathEncode(request.index.stream().map(v -> v).collect(Collectors.joining(",")), buf);
buf.append("/_rollup_search");
return buf.toString();
}
throw SimpleEndpoint.noPathTemplateFound("path");
},
// Request parameters
request -> {
return Collections.emptyMap();
}, SimpleEndpoint.emptyMap(), true, RollupSearchResponse._DESERIALIZER);
/**
* Create an "{@code rollup.rollup_search}" endpoint.
*/
public static Endpoint, ErrorResponse> createRollupSearchEndpoint(
JsonpDeserializer tDocumentDeserializer) {
return _ENDPOINT.withResponseDeserializer(
RollupSearchResponse.createRollupSearchResponseDeserializer(tDocumentDeserializer));
}
}