
io.polyglotted.eswrapper.query.StandardQuery Maven / Gradle / Ivy
package io.polyglotted.eswrapper.query;
import com.google.common.collect.ImmutableList;
import io.polyglotted.eswrapper.query.request.Expression;
import io.polyglotted.eswrapper.query.request.QueryHints;
import io.polyglotted.eswrapper.query.request.Sort;
import lombok.*;
import lombok.experimental.Accessors;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.copyOf;
import static io.polyglotted.eswrapper.query.request.QueryHints.hintsBuilder;
import static java.util.Arrays.asList;
@RequiredArgsConstructor
@ToString(includeFieldNames = false, doNotUseGetters = true)
public final class StandardQuery {
public final ImmutableList indices;
public final ImmutableList types;
public final ImmutableList fields;
public final ImmutableList expressions;
public final ImmutableList aggregates;
public final ImmutableList sorts;
public final QueryHints hints;
public final Long scroll;
public final int offset;
public final int size;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StandardQuery that = (StandardQuery) o;
return indices.equals(that.indices) && types.equals(that.types) && fields.equals(that.fields) &&
expressions.equals(that.expressions) && aggregates.equals(that.aggregates) && sorts.equals(that.sorts)
&& (hints == null ? that.hints == null : hints.equals(that.hints)) && (scroll == null ?
that.scroll == null : scroll.equals(that.scroll)) && offset == that.offset && size == that.size;
}
@Override
public int hashCode() {
return Objects.hash(indices, types, fields, expressions, aggregates, scroll, hints, scroll, offset, size);
}
public static Builder queryBuilder() {
return new Builder();
}
@Setter
@Accessors(fluent = true, chain = true)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public static class Builder {
private final List indices = new ArrayList<>();
private final List types = new ArrayList<>();
private final List fields = new ArrayList<>();
private final List expressions = new ArrayList<>();
private final List aggregates = new ArrayList<>();
private final List sorts = new ArrayList<>();
private QueryHints hints = hintsBuilder().build();
private Long scrollTimeInMillis = null;
private int offset = 0;
private int size = 10;
public Builder index(String... indices) {
this.indices.addAll(asList(indices));
return this;
}
public Builder type(String... types) {
this.types.addAll(asList(types));
return this;
}
public Builder field(String... fields) {
this.fields.addAll(asList(fields));
return this;
}
public Builder expression(Expression... expressions) {
this.expressions.addAll(asList(expressions));
return this;
}
public Builder aggregate(Expression... aggregates) {
this.aggregates.addAll(asList(aggregates));
return this;
}
public Builder sort(Sort.Builder sortBuilder) {
return sort(sortBuilder.build());
}
public Builder sort(Sort... sorts) {
this.sorts.addAll(asList(sorts));
return this;
}
public Builder hints(QueryHints.Builder hintBuilder) {
return hints(hintBuilder.build());
}
public Builder hints(QueryHints hints) {
this.hints = hints;
return this;
}
public StandardQuery build() {
return new StandardQuery(copyOf(indices), copyOf(types), copyOf(fields), copyOf(expressions),
copyOf(aggregates), copyOf(sorts), checkNotNull(hints), scrollTimeInMillis, offset, size);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy