E
- the type of entities to be queriedpublic class ElasticQuery<E extends ElasticEntity> extends Query<ElasticQuery<E>,E,ElasticConstraint>
Modifier and Type | Class and Description |
---|---|
class |
ElasticQuery.InnerHitsBuilder
Used to describe inner hits which are determine for field collapsing.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_TERM_AGGREGATION_BUCKET_COUNT
Contains the default number of buckets being collected and reported for an aggregation.
|
descriptor, limit, MAX_LIST_SIZE, mixing, skip
Constructor and Description |
---|
ElasticQuery(EntityDescriptor descriptor,
LowLevelClient client)
Creates a new query for the given type using the given client.
|
Modifier and Type | Method and Description |
---|---|
ElasticQuery<E> |
addAggregation(String name,
com.alibaba.fastjson.JSONObject aggregation)
Adds the given aggregation for the given name.
|
ElasticQuery.InnerHitsBuilder |
addCollapsedInnerHits(String name,
int size)
Adds a description to obtain a sublist of collapsed results.
|
ElasticQuery<E> |
addDateAggregation(String name,
Mapping field,
List<DateRange> ranges)
Adds a date (bucket) aggregation.
|
ElasticQuery<E> |
addTermAggregation(Mapping field)
Adds a term (bucket) aggregation for the given field.
|
ElasticQuery<E> |
addTermAggregation(String name,
Mapping field,
int size)
Adds a term (bucket) aggregation for the given field.
|
ElasticQuery<E> |
collapse(Mapping field)
Collapses by the given field.
|
ElasticQuery<E> |
collapse(String field)
Collapses by the given field.
|
void |
computeAggregations()
Executes a request which just contains aggregations and will not fetch any search items in the request body.
|
long |
count()
Executes the query and counts the number of results.
|
void |
delete()
Deletes all matches using the
BaseMapper.delete(BaseEntity) of the appropriate mapper. |
ElasticQuery<E> |
deliberatelyUnrouted()
Signals the the routing is deliberately skipped as no routing value is available.
|
boolean |
exists()
Determines if the query would have at least one matching entity.
|
ElasticQuery<E> |
filter(com.alibaba.fastjson.JSONObject filter)
Adds a FILTER constraint to the query.
|
FilterFactory<ElasticConstraint> |
filters() |
List<sirius.kernel.commons.Tuple<String,Integer>> |
getAggregationBuckets(String name)
Returns the buckets which were computed as an aggregation while executing the query.
|
void |
iterate(Function<E,Boolean> handler)
Calls the given function on all items in the result, as long as it returns true.
|
ElasticQuery<E> |
must(ElasticConstraint filter)
Adds a MUST filter to the query.
|
ElasticQuery<E> |
must(com.alibaba.fastjson.JSONObject filter)
Adds a MUST filter to the query.
|
ElasticQuery<E> |
mustNot(ElasticConstraint filter)
Adds a MUST NOT filter to the query.
|
ElasticQuery<E> |
mustNot(com.alibaba.fastjson.JSONObject filter)
Adds a MUST NOT filter to the query.
|
ElasticQuery<E> |
orderAsc(Mapping field)
Adds an ascending sort by the given field to the query.
|
ElasticQuery<E> |
orderDesc(Mapping field)
Adds a descending sort by the given field to the query.
|
ElasticQuery<E> |
postFilter(ElasticConstraint filter)
Adds a post filter to the query.
|
ElasticQuery<E> |
postFilter(com.alibaba.fastjson.JSONObject filter)
Adds a post filterto the query.
|
ElasticQuery<E> |
routing(String value)
Specifies the routing value to use.
|
ElasticQuery<E> |
sort(com.alibaba.fastjson.JSONObject sortSpec)
Adds a sort statement to the query.
|
ElasticQuery<E> |
sort(Mapping field,
com.alibaba.fastjson.JSONObject sortSpec)
Adds a sort statement for the given field to the query.
|
String |
toString() |
void |
truncate()
Deletes all matches using the capabilities of the underlying database.
|
ElasticQuery<E> |
where(ElasticConstraint constraint)
Applies the given contraints to the query.
|
ElasticQuery<E> |
years(int... years)
Specifies which years to query for entities which are
stored per year . |
ElasticQuery<E> |
yearsFromTo(int from,
int to)
Specifies a range of years to query for entities which are
stored per year . |
eq, eqIgnoreNull, ne, queryString
failOnOverflow, first, getDescriptor, getLimit, iterateAll, limit, one, queryFirst, queryList, queryOne, skip
public static final int DEFAULT_TERM_AGGREGATION_BUCKET_COUNT
public ElasticQuery(EntityDescriptor descriptor, LowLevelClient client)
descriptor
- the descriptor of the entity type to queryclient
- the client to useElastic.select(Class)
public ElasticQuery<E> years(int... years)
stored per year
.years
- a list of years to search in. Note that years for which no index exists will be filtered automaticallypublic ElasticQuery<E> yearsFromTo(int from, int to)
stored per year
.
Note that years for which no index exists will be filtered automatically
from
- the first year to search into
- the last year to search inpublic ElasticQuery<E> must(com.alibaba.fastjson.JSONObject filter)
filter
- the filter to addpublic ElasticQuery<E> must(ElasticConstraint filter)
filter
- the filter to addpublic ElasticQuery<E> mustNot(com.alibaba.fastjson.JSONObject filter)
filter
- the filter to addpublic ElasticQuery<E> mustNot(ElasticConstraint filter)
filter
- the filter to addpublic ElasticQuery<E> filter(com.alibaba.fastjson.JSONObject filter)
filter
- the filter to addBoolQueryBuilder.filter(JSONObject)
public ElasticQuery<E> where(ElasticConstraint constraint)
Query
where
in class Query<ElasticQuery<E extends ElasticEntity>,E extends ElasticEntity,ElasticConstraint>
constraint
- the constraint which has to be fullfilledpublic ElasticQuery<E> postFilter(com.alibaba.fastjson.JSONObject filter)
filter
- the filter to addpublic ElasticQuery<E> postFilter(ElasticConstraint filter)
filter
- the filter to addpublic ElasticQuery<E> sort(com.alibaba.fastjson.JSONObject sortSpec)
sortSpec
- a JSON object describing a sort requirementpublic ElasticQuery<E> sort(Mapping field, com.alibaba.fastjson.JSONObject sortSpec)
field
- the field to sort bysortSpec
- a JSON object describing a sort requirementpublic ElasticQuery<E> orderAsc(Mapping field)
orderAsc
in class Query<ElasticQuery<E extends ElasticEntity>,E extends ElasticEntity,ElasticConstraint>
field
- the field to order bypublic ElasticQuery<E> orderDesc(Mapping field)
orderDesc
in class Query<ElasticQuery<E extends ElasticEntity>,E extends ElasticEntity,ElasticConstraint>
field
- the field to order bypublic ElasticQuery<E> collapse(Mapping field)
field
- the field to collapse results by.public ElasticQuery<E> collapse(String field)
field
- the field to collapse results by.public ElasticQuery.InnerHitsBuilder addCollapsedInnerHits(String name, int size)
name
- the name of the listsize
- the number of resultspublic ElasticQuery<E> addAggregation(String name, com.alibaba.fastjson.JSONObject aggregation)
name
- the name of the aggregationaggregation
- the aggregation itselfpublic ElasticQuery<E> addTermAggregation(Mapping field)
field
- the field to aggregategetAggregationBuckets(String)
public ElasticQuery<E> addTermAggregation(String name, Mapping field, int size)
name
- the name of the aggregationfield
- the field to aggregatesize
- the max. number of buckets to returngetAggregationBuckets(String)
public ElasticQuery<E> addDateAggregation(String name, Mapping field, List<DateRange> ranges)
name
- the name of the aggregationfield
- the field to aggregateranges
- the ranges / buckets to aggregategetAggregationBuckets(String)
public ElasticQuery<E> routing(String value)
For routed entities it is highly recommended to supply a routing value as it greatly improves the
search performance. If no routing value is available, use deliberatelyUnrouted()
to signal
the the value was deliberately skipped. Otherwise a warning will be emitted to support error tracing.
value
- the value to use for routingpublic ElasticQuery<E> deliberatelyUnrouted()
public long count()
Query
count
in class Query<ElasticQuery<E extends ElasticEntity>,E extends ElasticEntity,ElasticConstraint>
public boolean exists()
Query
exists
in class Query<ElasticQuery<E extends ElasticEntity>,E extends ElasticEntity,ElasticConstraint>
public void iterate(Function<E,Boolean> handler)
BaseQuery
Note that this method is intended for large results as not all items in the result need to be kept in memory when iterating through them.
iterate
in class BaseQuery<ElasticQuery<E extends ElasticEntity>,E extends ElasticEntity>
handler
- the handle to be invoked for each item in the resultpublic void computeAggregations()
The computed aggregations can be read via getAggregationBuckets(String)
.
public List<sirius.kernel.commons.Tuple<String,Integer>> getAggregationBuckets(String name)
Note that the query has to be executed before calling this method.
name
- the aggregation to readpublic void delete()
Query
BaseMapper.delete(BaseEntity)
of the appropriate mapper.
Be aware that this might be slow for very large result sets.
delete
in class Query<ElasticQuery<E extends ElasticEntity>,E extends ElasticEntity,ElasticConstraint>
public void truncate()
Query
Therefore no checks or anything will be invoked for the deleted entities.
Use this for larger result sets where integrity and constraints do not matter or are managed manually.
truncate
in class Query<ElasticQuery<E extends ElasticEntity>,E extends ElasticEntity,ElasticConstraint>
public FilterFactory<ElasticConstraint> filters()
filters
in class Query<ElasticQuery<E extends ElasticEntity>,E extends ElasticEntity,ElasticConstraint>
Copyright © 2018. All rights reserved.