com.arakelian.elastic.model.search.ImmutableSearch Maven / Gradle / Ivy
package com.arakelian.elastic.model.search;
import com.arakelian.core.feature.Nullable;
import com.arakelian.elastic.model.aggs.Aggregation;
import com.arakelian.elastic.model.enums.SearchType;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import javax.annotation.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link Search}.
*
* Use the builder to create immutable instances:
* {@code ImmutableSearch.builder()}.
*/
@Generated(from = "Search", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableSearch implements Search {
private final ImmutableList aggregations;
private final @Nullable Integer batchedReduceSize;
private final @Nullable Integer from;
private final @Nullable Highlighter.Highlight highlight;
private final @Nullable String preference;
private final @Nullable Query query;
private final @Nullable String scroll;
private final @Nullable String scrollId;
private final @Nullable SearchType searchType;
private final @Nullable Integer size;
private final ImmutableList sorts;
private final @Nullable SourceFilter sourceFilter;
private final @Nullable ImmutableSet storedFields;
private final @Nullable Integer terminateAfter;
private final @Nullable String timeout;
private final @Nullable Boolean allowPartialSearchResults;
private final @Nullable Boolean explain;
private final @Nullable Boolean requestCache;
private final @Nullable Boolean trackScores;
private final @Nullable Boolean trackTotalHits;
private final @Nullable Boolean version;
private ImmutableSearch(ImmutableSearch.Builder builder) {
this.batchedReduceSize = builder.batchedReduceSize;
this.from = builder.from;
this.highlight = builder.highlight;
this.preference = builder.preference;
this.query = builder.query;
this.scroll = builder.scroll;
this.scrollId = builder.scrollId;
this.searchType = builder.searchType;
this.size = builder.size;
this.sourceFilter = builder.sourceFilter;
this.terminateAfter = builder.terminateAfter;
this.timeout = builder.timeout;
this.allowPartialSearchResults = builder.allowPartialSearchResults;
this.explain = builder.explain;
this.requestCache = builder.requestCache;
this.trackScores = builder.trackScores;
this.trackTotalHits = builder.trackTotalHits;
this.version = builder.version;
if (builder.aggregationsIsSet()) {
initShim.aggregations(builder.aggregations.build());
}
if (builder.sortsIsSet()) {
initShim.sorts(builder.sorts.build());
}
if (builder.storedFieldsIsSet()) {
initShim.storedFields(builder.storedFields == null ? null : builder.storedFields.build());
}
this.aggregations = initShim.getAggregations();
this.sorts = initShim.getSorts();
this.storedFields = initShim.getStoredFields();
this.initShim = null;
}
private static final byte STAGE_INITIALIZING = -1;
private static final byte STAGE_UNINITIALIZED = 0;
private static final byte STAGE_INITIALIZED = 1;
@SuppressWarnings("Immutable")
private transient volatile InitShim initShim = new InitShim();
@Generated(from = "Search", generator = "Immutables")
private final class InitShim {
private byte aggregationsBuildStage = STAGE_UNINITIALIZED;
private ImmutableList aggregations;
ImmutableList getAggregations() {
if (aggregationsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (aggregationsBuildStage == STAGE_UNINITIALIZED) {
aggregationsBuildStage = STAGE_INITIALIZING;
this.aggregations = ImmutableList.copyOf(getAggregationsInitialize());
aggregationsBuildStage = STAGE_INITIALIZED;
}
return this.aggregations;
}
void aggregations(ImmutableList aggregations) {
this.aggregations = aggregations;
aggregationsBuildStage = STAGE_INITIALIZED;
}
private byte sortsBuildStage = STAGE_UNINITIALIZED;
private ImmutableList sorts;
ImmutableList getSorts() {
if (sortsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (sortsBuildStage == STAGE_UNINITIALIZED) {
sortsBuildStage = STAGE_INITIALIZING;
this.sorts = ImmutableList.copyOf(getSortsInitialize());
sortsBuildStage = STAGE_INITIALIZED;
}
return this.sorts;
}
void sorts(ImmutableList sorts) {
this.sorts = sorts;
sortsBuildStage = STAGE_INITIALIZED;
}
private byte storedFieldsBuildStage = STAGE_UNINITIALIZED;
private ImmutableSet storedFields;
ImmutableSet getStoredFields() {
if (storedFieldsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (storedFieldsBuildStage == STAGE_UNINITIALIZED) {
storedFieldsBuildStage = STAGE_INITIALIZING;
this.storedFields = getStoredFieldsInitialize() == null ? null : ImmutableSet.copyOf(getStoredFieldsInitialize());
storedFieldsBuildStage = STAGE_INITIALIZED;
}
return this.storedFields;
}
void storedFields(ImmutableSet storedFields) {
this.storedFields = storedFields;
storedFieldsBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (aggregationsBuildStage == STAGE_INITIALIZING) attributes.add("aggregations");
if (sortsBuildStage == STAGE_INITIALIZING) attributes.add("sorts");
if (storedFieldsBuildStage == STAGE_INITIALIZING) attributes.add("storedFields");
return "Cannot build Search, attribute initializers form cycle " + attributes;
}
}
private List getAggregationsInitialize() {
return Search.super.getAggregations();
}
private List getSortsInitialize() {
return Search.super.getSorts();
}
private @Nullable Set getStoredFieldsInitialize() {
return Search.super.getStoredFields();
}
/**
* @return The value of the {@code aggregations} attribute
*/
@JsonProperty("aggregations")
@Override
public ImmutableList getAggregations() {
InitShim shim = this.initShim;
return shim != null
? shim.getAggregations()
: this.aggregations;
}
/**
* @return The value of the {@code batchedReduceSize} attribute
*/
@JsonProperty("batchedReduceSize")
@Override
public @Nullable Integer getBatchedReduceSize() {
return batchedReduceSize;
}
/**
* @return The value of the {@code from} attribute
*/
@JsonProperty("from")
@Override
public @Nullable Integer getFrom() {
return from;
}
/**
* @return The value of the {@code highlight} attribute
*/
@JsonProperty("highlight")
@Override
public @Nullable Highlighter.Highlight getHighlight() {
return highlight;
}
/**
* @return The value of the {@code preference} attribute
*/
@JsonProperty("preference")
@Override
public @Nullable String getPreference() {
return preference;
}
/**
* @return The value of the {@code query} attribute
*/
@JsonProperty("query")
@Override
public @Nullable Query getQuery() {
return query;
}
/**
* @return The value of the {@code scroll} attribute
*/
@JsonProperty("scroll")
@Override
public @Nullable String getScroll() {
return scroll;
}
/**
* @return The value of the {@code scrollId} attribute
*/
@JsonProperty("scrollId")
@Override
public @Nullable String getScrollId() {
return scrollId;
}
/**
* @return The value of the {@code searchType} attribute
*/
@JsonProperty("searchType")
@Override
public @Nullable SearchType getSearchType() {
return searchType;
}
/**
* @return The value of the {@code size} attribute
*/
@JsonProperty("size")
@Override
public @Nullable Integer getSize() {
return size;
}
/**
* @return The value of the {@code sorts} attribute
*/
@JsonProperty("sorts")
@Override
public ImmutableList getSorts() {
InitShim shim = this.initShim;
return shim != null
? shim.getSorts()
: this.sorts;
}
/**
* @return The value of the {@code sourceFilter} attribute
*/
@JsonProperty("_source")
@Override
public @Nullable SourceFilter getSourceFilter() {
return sourceFilter;
}
/**
* Returns a list of JSON fields that are explicitly stored in the mapping and should be
* returned with search hits. Elastic recommends using source filtering instead to select
* subsets of the original source document to be returned.
*
* * can be used to load all stored fields from the document.
* _none_ can be used to disable returning stored fields and metadata fields
* entirely
* - An empty array will cause only the _id and _type for each hit to be returned
* - Only leaf fields can be returned; object fields can't be returned and such requests will
* fail.
*
* @return a list of JSON fields that are explicitly stored in the mapping and should be
* returned with search hits
*/
@JsonProperty("stored_fields")
@Override
public @Nullable ImmutableSet getStoredFields() {
InitShim shim = this.initShim;
return shim != null
? shim.getStoredFields()
: this.storedFields;
}
/**
* Returns the maximum number of documents to collect for each shard, upon reaching which the
* query execution will terminate early. If set, the response will have a boolean field
* terminated_early to indicate whether the query execution has actually terminated_early.
* @return the maximum number of documents to collect for each shard
*/
@JsonProperty("terminateAfter")
@Override
public @Nullable Integer getTerminateAfter() {
return terminateAfter;
}
/**
* Returns the explicit operation timeout, e.g. "20s"
* @return the explicit operation timeout
*/
@JsonProperty("timeout")
@Override
public @Nullable String getTimeout() {
return timeout;
}
/**
* Returns true if an error should be returned if there is a partial search failure or timeout
* @return true if an error should be returned if there is a partial search failure or timeout
*/
@JsonProperty("allowPartialSearchResults")
@Override
public @Nullable Boolean isAllowPartialSearchResults() {
return allowPartialSearchResults;
}
/**
* @return The value of the {@code explain} attribute
*/
@JsonProperty("explain")
@Override
public @Nullable Boolean isExplain() {
return explain;
}
/**
* Returns true to enable caching of search results for requests where size is 0, ie
* aggregations and suggestions (no top hits returned).
* @return true to enable caching of search results
*/
@JsonProperty("requestCache")
@Override
public @Nullable Boolean isRequestCache() {
return requestCache;
}
/**
* Returns true to calculate and return scores even if they are not used for sorting
* @return true to calculate and return scores even if they are not used for sorting
*/
@JsonProperty("trackScores")
@Override
public @Nullable Boolean isTrackScores() {
return trackScores;
}
/**
* Returns true if the number of documents that match the query should be tracked
* @return true if the number of documents that match the query should be tracked
*/
@JsonProperty("trackTotalHits")
@Override
public @Nullable Boolean isTrackTotalHits() {
return trackTotalHits;
}
/**
* @return The value of the {@code version} attribute
*/
@JsonProperty("version")
@Override
public @Nullable Boolean isVersion() {
return version;
}
/**
* This instance is equal to all instances of {@code ImmutableSearch} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@javax.annotation.Nullable Object another) {
if (this == another) return true;
return another instanceof ImmutableSearch
&& equalTo((ImmutableSearch) another);
}
private boolean equalTo(ImmutableSearch another) {
return aggregations.equals(another.aggregations)
&& Objects.equals(batchedReduceSize, another.batchedReduceSize)
&& Objects.equals(from, another.from)
&& Objects.equals(highlight, another.highlight)
&& Objects.equals(preference, another.preference)
&& Objects.equals(query, another.query)
&& Objects.equals(scroll, another.scroll)
&& Objects.equals(scrollId, another.scrollId)
&& Objects.equals(searchType, another.searchType)
&& Objects.equals(size, another.size)
&& sorts.equals(another.sorts)
&& Objects.equals(sourceFilter, another.sourceFilter)
&& Objects.equals(storedFields, another.storedFields)
&& Objects.equals(terminateAfter, another.terminateAfter)
&& Objects.equals(timeout, another.timeout)
&& Objects.equals(allowPartialSearchResults, another.allowPartialSearchResults)
&& Objects.equals(explain, another.explain)
&& Objects.equals(requestCache, another.requestCache)
&& Objects.equals(trackScores, another.trackScores)
&& Objects.equals(trackTotalHits, another.trackTotalHits)
&& Objects.equals(version, another.version);
}
/**
* Computes a hash code from attributes: {@code aggregations}, {@code batchedReduceSize}, {@code from}, {@code highlight}, {@code preference}, {@code query}, {@code scroll}, {@code scrollId}, {@code searchType}, {@code size}, {@code sorts}, {@code sourceFilter}, {@code storedFields}, {@code terminateAfter}, {@code timeout}, {@code allowPartialSearchResults}, {@code explain}, {@code requestCache}, {@code trackScores}, {@code trackTotalHits}, {@code version}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + aggregations.hashCode();
h += (h << 5) + Objects.hashCode(batchedReduceSize);
h += (h << 5) + Objects.hashCode(from);
h += (h << 5) + Objects.hashCode(highlight);
h += (h << 5) + Objects.hashCode(preference);
h += (h << 5) + Objects.hashCode(query);
h += (h << 5) + Objects.hashCode(scroll);
h += (h << 5) + Objects.hashCode(scrollId);
h += (h << 5) + Objects.hashCode(searchType);
h += (h << 5) + Objects.hashCode(size);
h += (h << 5) + sorts.hashCode();
h += (h << 5) + Objects.hashCode(sourceFilter);
h += (h << 5) + Objects.hashCode(storedFields);
h += (h << 5) + Objects.hashCode(terminateAfter);
h += (h << 5) + Objects.hashCode(timeout);
h += (h << 5) + Objects.hashCode(allowPartialSearchResults);
h += (h << 5) + Objects.hashCode(explain);
h += (h << 5) + Objects.hashCode(requestCache);
h += (h << 5) + Objects.hashCode(trackScores);
h += (h << 5) + Objects.hashCode(trackTotalHits);
h += (h << 5) + Objects.hashCode(version);
return h;
}
/**
* Prints the immutable value {@code Search} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Search")
.omitNullValues()
.add("aggregations", aggregations)
.add("batchedReduceSize", batchedReduceSize)
.add("from", from)
.add("highlight", highlight)
.add("preference", preference)
.add("query", query)
.add("scroll", scroll)
.add("scrollId", scrollId)
.add("searchType", searchType)
.add("size", size)
.add("sorts", sorts)
.add("sourceFilter", sourceFilter)
.add("storedFields", storedFields)
.add("terminateAfter", terminateAfter)
.add("timeout", timeout)
.add("allowPartialSearchResults", allowPartialSearchResults)
.add("explain", explain)
.add("requestCache", requestCache)
.add("trackScores", trackScores)
.add("trackTotalHits", trackTotalHits)
.add("version", version)
.toString();
}
/**
* Creates a builder for {@link ImmutableSearch ImmutableSearch}.
*
* ImmutableSearch.builder()
* .addAggregation|addAllAggregations(com.arakelian.elastic.model.aggs.Aggregation) // {@link Search#getAggregations() aggregations} elements
* .batchedReduceSize(Integer | null) // nullable {@link Search#getBatchedReduceSize() batchedReduceSize}
* .from(Integer | null) // nullable {@link Search#getFrom() from}
* .highlight(com.arakelian.elastic.model.search.Highlighter.Highlight | null) // nullable {@link Search#getHighlight() highlight}
* .preference(String | null) // nullable {@link Search#getPreference() preference}
* .query(com.arakelian.elastic.model.search.Query | null) // nullable {@link Search#getQuery() query}
* .scroll(String | null) // nullable {@link Search#getScroll() scroll}
* .scrollId(String | null) // nullable {@link Search#getScrollId() scrollId}
* .searchType(com.arakelian.elastic.model.enums.SearchType | null) // nullable {@link Search#getSearchType() searchType}
* .size(Integer | null) // nullable {@link Search#getSize() size}
* .addSort|addAllSorts(com.arakelian.elastic.model.search.Sort) // {@link Search#getSorts() sorts} elements
* .sourceFilter(com.arakelian.elastic.model.search.SourceFilter | null) // nullable {@link Search#getSourceFilter() sourceFilter}
* .storedFields(Set<String> | null) // nullable {@link Search#getStoredFields() storedFields}
* .terminateAfter(Integer | null) // nullable {@link Search#getTerminateAfter() terminateAfter}
* .timeout(String | null) // nullable {@link Search#getTimeout() timeout}
* .allowPartialSearchResults(Boolean | null) // nullable {@link Search#isAllowPartialSearchResults() allowPartialSearchResults}
* .explain(Boolean | null) // nullable {@link Search#isExplain() explain}
* .requestCache(Boolean | null) // nullable {@link Search#isRequestCache() requestCache}
* .trackScores(Boolean | null) // nullable {@link Search#isTrackScores() trackScores}
* .trackTotalHits(Boolean | null) // nullable {@link Search#isTrackTotalHits() trackTotalHits}
* .version(Boolean | null) // nullable {@link Search#isVersion() version}
* .build();
*
* @return A new ImmutableSearch builder
*/
public static ImmutableSearch.Builder builder() {
return new ImmutableSearch.Builder();
}
/**
* Builds instances of type {@link ImmutableSearch ImmutableSearch}.
* Initialize attributes and then invoke the {@link #build()} method to create an
* immutable instance.
* {@code Builder} is not thread-safe and generally should not be stored in a field or collection,
* but instead used immediately to create instances.
*/
@Generated(from = "Search", generator = "Immutables")
@NotThreadSafe
@JsonPropertyOrder({"scroll", "scrollId", "from", "size", "searchType", "terminateAfter", "_source", "stored_fields", "query", "sort", "aggregation", "version", "explain", "batchedReduceSize", "preference"})
public static final class Builder {
private static final long OPT_BIT_AGGREGATIONS = 0x1L;
private static final long OPT_BIT_SORTS = 0x2L;
private static final long OPT_BIT_STORED_FIELDS = 0x4L;
private long optBits;
private ImmutableList.Builder aggregations = ImmutableList.builder();
private @javax.annotation.Nullable Integer batchedReduceSize;
private @javax.annotation.Nullable Integer from;
private @javax.annotation.Nullable Highlighter.Highlight highlight;
private @javax.annotation.Nullable String preference;
private @javax.annotation.Nullable Query query;
private @javax.annotation.Nullable String scroll;
private @javax.annotation.Nullable String scrollId;
private @javax.annotation.Nullable SearchType searchType;
private @javax.annotation.Nullable Integer size;
private ImmutableList.Builder sorts = ImmutableList.builder();
private @javax.annotation.Nullable SourceFilter sourceFilter;
private ImmutableSet.Builder storedFields = null;
private @javax.annotation.Nullable Integer terminateAfter;
private @javax.annotation.Nullable String timeout;
private @javax.annotation.Nullable Boolean allowPartialSearchResults;
private @javax.annotation.Nullable Boolean explain;
private @javax.annotation.Nullable Boolean requestCache;
private @javax.annotation.Nullable Boolean trackScores;
private @javax.annotation.Nullable Boolean trackTotalHits;
private @javax.annotation.Nullable Boolean version;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code Search} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder using(Search instance) {
Objects.requireNonNull(instance, "instance");
addAllAggregations(instance.getAggregations());
Integer batchedReduceSizeValue = instance.getBatchedReduceSize();
if (batchedReduceSizeValue != null) {
batchedReduceSize(batchedReduceSizeValue);
}
Integer fromValue = instance.getFrom();
if (fromValue != null) {
from(fromValue);
}
Highlighter.Highlight highlightValue = instance.getHighlight();
if (highlightValue != null) {
highlight(highlightValue);
}
String preferenceValue = instance.getPreference();
if (preferenceValue != null) {
preference(preferenceValue);
}
Query queryValue = instance.getQuery();
if (queryValue != null) {
query(queryValue);
}
String scrollValue = instance.getScroll();
if (scrollValue != null) {
scroll(scrollValue);
}
String scrollIdValue = instance.getScrollId();
if (scrollIdValue != null) {
scrollId(scrollIdValue);
}
SearchType searchTypeValue = instance.getSearchType();
if (searchTypeValue != null) {
searchType(searchTypeValue);
}
Integer sizeValue = instance.getSize();
if (sizeValue != null) {
size(sizeValue);
}
addAllSorts(instance.getSorts());
SourceFilter sourceFilterValue = instance.getSourceFilter();
if (sourceFilterValue != null) {
sourceFilter(sourceFilterValue);
}
Set storedFieldsValue = instance.getStoredFields();
if (storedFieldsValue != null) {
addAllStoredFields(storedFieldsValue);
}
Integer terminateAfterValue = instance.getTerminateAfter();
if (terminateAfterValue != null) {
terminateAfter(terminateAfterValue);
}
String timeoutValue = instance.getTimeout();
if (timeoutValue != null) {
timeout(timeoutValue);
}
Boolean allowPartialSearchResultsValue = instance.isAllowPartialSearchResults();
if (allowPartialSearchResultsValue != null) {
allowPartialSearchResults(allowPartialSearchResultsValue);
}
Boolean explainValue = instance.isExplain();
if (explainValue != null) {
explain(explainValue);
}
Boolean requestCacheValue = instance.isRequestCache();
if (requestCacheValue != null) {
requestCache(requestCacheValue);
}
Boolean trackScoresValue = instance.isTrackScores();
if (trackScoresValue != null) {
trackScores(trackScoresValue);
}
Boolean trackTotalHitsValue = instance.isTrackTotalHits();
if (trackTotalHitsValue != null) {
trackTotalHits(trackTotalHitsValue);
}
Boolean versionValue = instance.isVersion();
if (versionValue != null) {
version(versionValue);
}
return this;
}
/**
* Adds one element to {@link Search#getAggregations() aggregations} list.
* @param element A aggregations element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAggregation(Aggregation element) {
this.aggregations.add(element);
optBits |= OPT_BIT_AGGREGATIONS;
return this;
}
/**
* Adds elements to {@link Search#getAggregations() aggregations} list.
* @param elements An array of aggregations elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAggregations(Aggregation... elements) {
this.aggregations.add(elements);
optBits |= OPT_BIT_AGGREGATIONS;
return this;
}
/**
* Sets or replaces all elements for {@link Search#getAggregations() aggregations} list.
* @param elements An iterable of aggregations elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("aggregations")
public final Builder aggregations(Iterable extends Aggregation> elements) {
this.aggregations = ImmutableList.builder();
return addAllAggregations(elements);
}
/**
* Adds elements to {@link Search#getAggregations() aggregations} list.
* @param elements An iterable of aggregations elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllAggregations(Iterable extends Aggregation> elements) {
this.aggregations.addAll(elements);
optBits |= OPT_BIT_AGGREGATIONS;
return this;
}
/**
* Initializes the value for the {@link Search#getBatchedReduceSize() batchedReduceSize} attribute.
* @param batchedReduceSize The value for batchedReduceSize (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("batchedReduceSize")
public final Builder batchedReduceSize(@Nullable Integer batchedReduceSize) {
this.batchedReduceSize = batchedReduceSize;
return this;
}
/**
* Initializes the value for the {@link Search#getFrom() from} attribute.
* @param from The value for from (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("from")
public final Builder from(@Nullable Integer from) {
this.from = from;
return this;
}
/**
* Initializes the value for the {@link Search#getHighlight() highlight} attribute.
* @param highlight The value for highlight (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("highlight")
public final Builder highlight(@Nullable Highlighter.Highlight highlight) {
this.highlight = highlight;
return this;
}
/**
* Initializes the value for the {@link Search#getPreference() preference} attribute.
* @param preference The value for preference (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("preference")
public final Builder preference(@Nullable String preference) {
this.preference = preference;
return this;
}
/**
* Initializes the value for the {@link Search#getQuery() query} attribute.
* @param query The value for query (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("query")
public final Builder query(@Nullable Query query) {
this.query = query;
return this;
}
/**
* Initializes the value for the {@link Search#getScroll() scroll} attribute.
* @param scroll The value for scroll (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("scroll")
public final Builder scroll(@Nullable String scroll) {
this.scroll = scroll;
return this;
}
/**
* Initializes the value for the {@link Search#getScrollId() scrollId} attribute.
* @param scrollId The value for scrollId (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("scrollId")
public final Builder scrollId(@Nullable String scrollId) {
this.scrollId = scrollId;
return this;
}
/**
* Initializes the value for the {@link Search#getSearchType() searchType} attribute.
* @param searchType The value for searchType (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("searchType")
public final Builder searchType(@Nullable SearchType searchType) {
this.searchType = searchType;
return this;
}
/**
* Initializes the value for the {@link Search#getSize() size} attribute.
* @param size The value for size (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("size")
public final Builder size(@Nullable Integer size) {
this.size = size;
return this;
}
/**
* Adds one element to {@link Search#getSorts() sorts} list.
* @param element A sorts element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addSort(Sort element) {
this.sorts.add(element);
optBits |= OPT_BIT_SORTS;
return this;
}
/**
* Adds elements to {@link Search#getSorts() sorts} list.
* @param elements An array of sorts elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addSorts(Sort... elements) {
this.sorts.add(elements);
optBits |= OPT_BIT_SORTS;
return this;
}
/**
* Sets or replaces all elements for {@link Search#getSorts() sorts} list.
* @param elements An iterable of sorts elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("sorts")
public final Builder sorts(Iterable extends Sort> elements) {
this.sorts = ImmutableList.builder();
return addAllSorts(elements);
}
/**
* Adds elements to {@link Search#getSorts() sorts} list.
* @param elements An iterable of sorts elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllSorts(Iterable extends Sort> elements) {
this.sorts.addAll(elements);
optBits |= OPT_BIT_SORTS;
return this;
}
/**
* Initializes the value for the {@link Search#getSourceFilter() sourceFilter} attribute.
* @param sourceFilter The value for sourceFilter (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_source")
public final Builder sourceFilter(@Nullable SourceFilter sourceFilter) {
this.sourceFilter = sourceFilter;
return this;
}
/**
* Adds one element to {@link Search#getStoredFields() storedFields} set.
* @param element A storedFields element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addStoredField(String element) {
if (this.storedFields == null) {
this.storedFields = ImmutableSet.builder();
}
this.storedFields.add(element);
optBits |= OPT_BIT_STORED_FIELDS;
return this;
}
/**
* Adds elements to {@link Search#getStoredFields() storedFields} set.
* @param elements An array of storedFields elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addStoredFields(String... elements) {
if (this.storedFields == null) {
this.storedFields = ImmutableSet.builder();
}
this.storedFields.add(elements);
optBits |= OPT_BIT_STORED_FIELDS;
return this;
}
/**
* Sets or replaces all elements for {@link Search#getStoredFields() storedFields} set.
* @param elements An iterable of storedFields elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("stored_fields")
public final Builder storedFields(@Nullable Iterable elements) {
if (elements == null) {
this.storedFields = null;
optBits |= OPT_BIT_STORED_FIELDS;
return this;
}
this.storedFields = ImmutableSet.builder();
return addAllStoredFields(elements);
}
/**
* Adds elements to {@link Search#getStoredFields() storedFields} set.
* @param elements An iterable of storedFields elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllStoredFields(Iterable elements) {
Objects.requireNonNull(elements, "storedFields element");
if (this.storedFields == null) {
this.storedFields = ImmutableSet.builder();
}
this.storedFields.addAll(elements);
optBits |= OPT_BIT_STORED_FIELDS;
return this;
}
/**
* Initializes the value for the {@link Search#getTerminateAfter() terminateAfter} attribute.
* @param terminateAfter The value for terminateAfter (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("terminateAfter")
public final Builder terminateAfter(@Nullable Integer terminateAfter) {
this.terminateAfter = terminateAfter;
return this;
}
/**
* Initializes the value for the {@link Search#getTimeout() timeout} attribute.
* @param timeout The value for timeout (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("timeout")
public final Builder timeout(@Nullable String timeout) {
this.timeout = timeout;
return this;
}
/**
* Initializes the value for the {@link Search#isAllowPartialSearchResults() allowPartialSearchResults} attribute.
* @param allowPartialSearchResults The value for allowPartialSearchResults (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("allowPartialSearchResults")
public final Builder allowPartialSearchResults(@Nullable Boolean allowPartialSearchResults) {
this.allowPartialSearchResults = allowPartialSearchResults;
return this;
}
/**
* Initializes the value for the {@link Search#isExplain() explain} attribute.
* @param explain The value for explain (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("explain")
public final Builder explain(@Nullable Boolean explain) {
this.explain = explain;
return this;
}
/**
* Initializes the value for the {@link Search#isRequestCache() requestCache} attribute.
* @param requestCache The value for requestCache (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("requestCache")
public final Builder requestCache(@Nullable Boolean requestCache) {
this.requestCache = requestCache;
return this;
}
/**
* Initializes the value for the {@link Search#isTrackScores() trackScores} attribute.
* @param trackScores The value for trackScores (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("trackScores")
public final Builder trackScores(@Nullable Boolean trackScores) {
this.trackScores = trackScores;
return this;
}
/**
* Initializes the value for the {@link Search#isTrackTotalHits() trackTotalHits} attribute.
* @param trackTotalHits The value for trackTotalHits (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("trackTotalHits")
public final Builder trackTotalHits(@Nullable Boolean trackTotalHits) {
this.trackTotalHits = trackTotalHits;
return this;
}
/**
* Initializes the value for the {@link Search#isVersion() version} attribute.
* @param version The value for version (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("version")
public final Builder version(@Nullable Boolean version) {
this.version = version;
return this;
}
/**
* Builds a new {@link ImmutableSearch ImmutableSearch}.
* @return An immutable instance of Search
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSearch build() {
return new ImmutableSearch(this);
}
private boolean aggregationsIsSet() {
return (optBits & OPT_BIT_AGGREGATIONS) != 0;
}
private boolean sortsIsSet() {
return (optBits & OPT_BIT_SORTS) != 0;
}
private boolean storedFieldsIsSet() {
return (optBits & OPT_BIT_STORED_FIELDS) != 0;
}
}
}