Module spring.data.elasticsearch
Class Criteria
java.lang.Object
org.springframework.data.elasticsearch.core.query.Criteria
Criteria is the central class when constructing queries. It follows more or less a fluent API style, which allows to
easily chain together multiple criteria.
A Criteria references a field and has
A Criteria also has a
A Criteria references a field and has
Criteria.CriteriaEntry sets for query and filter context. When building the
query, the entries from the criteria entries are combined in a bool must query (if more than one.A Criteria also has a
Criteria.CriteriaChain which is used to build a collection of Criteria with the fluent API. The
value of isAnd() and isOr() describes whether the queries built from the criteria chain should be
put in a must (and) or a should (or) clause when a query is built from it, it is not used to build some relationship
between the elements of the criteria chain.- Author:
- Rizwan Idrees, Mohsin Husen, Franck Marchand, Peter-Josef Meisch, Ezequiel AntĂșnez Camacho
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionCriteria()Creates a new Criteria with provided field nameprotectedCreates a Criteria for the given field, sets it's criteriaChain to the given value and adds itself to the end of the chain.protectedCreates a Criteria for the given field, sets it's criteriaChain to the given value and adds itself to the end of the chain.Creates a new Criteria for the given field -
Method Summary
Modifier and TypeMethodDescriptionstatic Criteriaand()Chain a new and- CriteriaChain a Criteria to this object.Chain an array of Criteria to this object.Chain a new and-CriteriaAdds a OperationKey.BETWEEN entry to thequeryCriteriaEntries.boost(float boost) Sets the boost factor.Adds a new filter CriteriaEntry for bounding box created from pointsAdds a new filter CriteriaEntry forlocation GeoBox bounding boxAdds a new filter CriteriaEntry for bounding box created from pointsAdds a new filter CriteriaEntry forlocation Box bounding boxAdds a new filter CriteriaEntry for bounding box created from pointsAdd aCriteria.OperationKey.CONTAINSentry to thequeryCriteriaEntries
NOTE: mind your schema as leading wildcards may not be supported and/or execution might be slow.Adds a new filter CriteriaEntry for GEO_CONTAINS.empty()Add aCriteria.OperationKey.EMPTYentry to thequeryCriteriaEntries.Add aCriteria.OperationKey.ENDS_WITHentry to thequeryCriteriaEntries
NOTE: mind your schema as leading wildcards may not be supported and/or execution might be slow.booleanexists()Add aCriteria.OperationKey.EXISTSentry to thequeryCriteriaEntriesexpression(String s) Add aCriteria.OperationKey.EXPRESSIONentry to thequeryCriteriaEntriesallowing native elasticsearch expressionsAdd aCriteria.OperationKey.FUZZYentry to thequeryCriteriaEntriesfloatgetBoost()getField()greaterThan(Object lowerBound) Add aCriteria.OperationKey.GREATERentry to thequeryCriteriaEntriesgreaterThanEqual(Object lowerBound) Add aCriteria.OperationKey.GREATER_EQUALentry to thequeryCriteriaEntrieshasChild(HasChildQuery query) Adds a new filter CriteriaEntry for HAS_CHILD.inthashCode()hasParent(HasParentQuery query) Adds a new filter CriteriaEntry for HAS_PARENT.Add aCriteria.OperationKey.INentry to thequeryCriteriaEntries.Add aCriteria.OperationKey.INentry to thequeryCriteriaEntries.intersects(GeoJson<?> geoShape) Adds a new filter CriteriaEntry for GEO_INTERSECTS.Add aCriteria.OperationKey.EQUALSentry to thequeryCriteriaEntriesbooleanisAnd()isDisjoint(GeoJson<?> geoShape) Adds a new filter CriteriaEntry for GEO_IS_DISJOINT.booleanbooleanisOr()Add aCriteria.OperationKey.LESSentry to thequeryCriteriaEntrieslessThanEqual(Object upperBound) Add aCriteria.OperationKey.LESS_EQUALentry to thequeryCriteriaEntriesAdd aCriteria.OperationKey.MATCHESentry to thequeryCriteriaEntries.matchesAll(Object value) Add aCriteria.OperationKey.MATCHESentry to thequeryCriteriaEntries.not()Sets the negating flagnotEmpty()Add aCriteria.OperationKey.NOT_EMPTYentry to thequeryCriteriaEntries.Add aCriteria.OperationKey.NOT_INentry to thequeryCriteriaEntries.Add aCriteria.OperationKey.NOT_INentry to thequeryCriteriaEntries.static Criteriaor()Chain a new or-CriteriaChain a new or-Criteria.Chain a new or-CriteriaAdd aCriteria.OperationKey.REGEXPentry to thequeryCriteriaEntries.startsWith(String s) Add aCriteria.OperationKey.STARTS_WITHentry to thequeryCriteriaEntriessubCriteria(Criteria criteria) adds a Criteria as subCriteriatoString()static CriteriaStatic factory method to create a new Criteria for field with given namestatic CriteriaStatic factory method to create a new Criteria for provided fieldAdds a new filter CriteriaEntry forgeoLocation WITHIN distanceAdds a new filter CriteriaEntry for GEO_WITHIN.Adds a new filter CriteriaEntry forlocation WITHIN distanceAdds a new filter CriteriaEntry forlocation WITHIN distance
-
Field Details
-
CRITERIA_VALUE_SEPARATOR
- See Also:
-
-
Constructor Details
-
Criteria
public Criteria() -
Criteria
Creates a new Criteria with provided field name- Parameters:
fieldName- the field name
-
Criteria
Creates a new Criteria for the given field- Parameters:
field- field to create the Criteria for
-
Criteria
Creates a Criteria for the given field, sets it's criteriaChain to the given value and adds itself to the end of the chain.- Parameters:
criteriaChain- the chain to add tofieldName- field to create the Criteria for
-
Criteria
Creates a Criteria for the given field, sets it's criteriaChain to the given value and adds itself to the end of the chain.- Parameters:
criteriaChain- the chain to add tofield- field to create the Criteria for
-
-
Method Details
-
and
- Returns:
- factory method to create an and-Criteria that is not bound to a field
- Since:
- 4.1
-
or
- Returns:
- factory method to create an or-Criteria that is not bound to a field
- Since:
- 4.1
-
where
Static factory method to create a new Criteria for field with given name- Parameters:
fieldName- field to create the Criteria for
-
where
Static factory method to create a new Criteria for provided field- Parameters:
field- field to create the Criteria for
-
getField
- Returns:
- the Field targeted by this Criteria
-
getQueryCriteriaEntries
-
getFilterCriteriaEntries
-
getOperator
-
getCriteriaChain
-
not
Sets the negating flag- Returns:
- this object
-
isNegating
public boolean isNegating() -
boost
Sets the boost factor.- Parameters:
boost- boost factor- Returns:
- this object
-
getBoost
public float getBoost() -
isAnd
public boolean isAnd() -
isOr
public boolean isOr() -
getSubCriteria
- Returns:
- the set ob subCriteria
- Since:
- 4.1
-
and
Chain a new and-Criteria- Parameters:
field- the field for the new Criteria- Returns:
- the new chained Criteria
-
and
Chain a new and- Criteria- Parameters:
fieldName- the field for the new Criteria- Returns:
- the new chained Criteria
-
and
Chain a Criteria to this object.- Parameters:
criteria- the Criteria to add- Returns:
- this object
-
and
Chain an array of Criteria to this object.- Parameters:
criterias- the Criteria to add- Returns:
- this object
-
or
Chain a new or-Criteria- Parameters:
field- the field for the new Criteria- Returns:
- the new chained Criteria
-
or
Chain a new or-Criteria- Parameters:
fieldName- the field for the new Criteria- Returns:
- the new chained Criteria
-
or
Chain a new or-Criteria. The new Criteria uses thegetField(),getQueryCriteriaEntries()andgetFilterCriteriaEntries()of the passed in parameter. the new created criteria is added to the criteria chain.- Parameters:
criteria- contains the information for the new Criteria- Returns:
- the new chained criteria
-
subCriteria
adds a Criteria as subCriteria- Parameters:
criteria- the criteria to add, must not be null- Returns:
- this object
- Since:
- 4.1
-
is
Add aCriteria.OperationKey.EQUALSentry to thequeryCriteriaEntries- Parameters:
o- the argument to the operation- Returns:
- this object
-
exists
Add aCriteria.OperationKey.EXISTSentry to thequeryCriteriaEntries- Returns:
- this object
- Since:
- 4.0
-
between
Adds a OperationKey.BETWEEN entry to thequeryCriteriaEntries. Only one of the parameters may be null to define an unbounded end of the range.- Parameters:
lowerBound- the lower bound of the range, null for unboundedupperBound- the upper bound of the range, null for unbounded- Returns:
- this object
-
startsWith
Add aCriteria.OperationKey.STARTS_WITHentry to thequeryCriteriaEntries- Parameters:
s- the argument to the operation- Returns:
- this object
-
contains
Add aCriteria.OperationKey.CONTAINSentry to thequeryCriteriaEntries
NOTE: mind your schema as leading wildcards may not be supported and/or execution might be slow.- Parameters:
s- the argument to the operation- Returns:
- this object
-
endsWith
Add aCriteria.OperationKey.ENDS_WITHentry to thequeryCriteriaEntries
NOTE: mind your schema as leading wildcards may not be supported and/or execution might be slow.- Parameters:
s- the argument to the operation- Returns:
- this object
-
in
Add aCriteria.OperationKey.INentry to thequeryCriteriaEntries. This will create a terms query, so don't use it with text fields as these are analyzed and changed by Elasticsearch (converted to lowercase with the default analyzer). If used for Strings, these should be marked as field type Keyword.- Parameters:
values- the argument to the operation- Returns:
- this object
-
in
- Parameters:
values- the argument to the operation- Returns:
- this object
-
notIn
Add aCriteria.OperationKey.NOT_INentry to thequeryCriteriaEntries. See the comment atin(Object...).- Parameters:
values- the argument to the operation- Returns:
- this object
-
notIn
Add aCriteria.OperationKey.NOT_INentry to thequeryCriteriaEntries. See the comment atin(Object...).- Parameters:
values- the argument to the operation- Returns:
- this object
-
expression
Add aCriteria.OperationKey.EXPRESSIONentry to thequeryCriteriaEntriesallowing native elasticsearch expressions- Parameters:
s- the argument to the operation- Returns:
- this object
-
fuzzy
Add aCriteria.OperationKey.FUZZYentry to thequeryCriteriaEntries- Parameters:
s- the argument to the operation- Returns:
- this object
-
lessThanEqual
Add aCriteria.OperationKey.LESS_EQUALentry to thequeryCriteriaEntries- Parameters:
upperBound- the argument to the operation- Returns:
- this object
-
lessThan
Add aCriteria.OperationKey.LESSentry to thequeryCriteriaEntries- Parameters:
upperBound- the argument to the operation- Returns:
- this object
-
greaterThanEqual
Add aCriteria.OperationKey.GREATER_EQUALentry to thequeryCriteriaEntries- Parameters:
lowerBound- the argument to the operation- Returns:
- this object
-
greaterThan
Add aCriteria.OperationKey.GREATERentry to thequeryCriteriaEntries- Parameters:
lowerBound- the argument to the operation- Returns:
- this object
-
matches
Add aCriteria.OperationKey.MATCHESentry to thequeryCriteriaEntries. This will build a match query with the OR operator.- Parameters:
value- the value to match- Returns:
- this object
- Since:
- 4.1
-
matchesAll
Add aCriteria.OperationKey.MATCHESentry to thequeryCriteriaEntries. This will build a match query with the AND operator.- Parameters:
value- the value to match- Returns:
- this object
- Since:
- 4.1
-
empty
Add aCriteria.OperationKey.EMPTYentry to thequeryCriteriaEntries.- Returns:
- this object
- Since:
- 4.3
-
notEmpty
Add aCriteria.OperationKey.NOT_EMPTYentry to thequeryCriteriaEntries.- Returns:
- this object
- Since:
- 4.3
-
regexp
Add aCriteria.OperationKey.REGEXPentry to thequeryCriteriaEntries.- Parameters:
value- the regexp value to match- Returns:
- this object
- Since:
- 5.1
-
boundedBy
Adds a new filter CriteriaEntry forlocation GeoBox bounding box- Parameters:
boundingBox-GeoBoxbounding box(left top corner + right bottom corner)- Returns:
- this object
-
boundedBy
Adds a new filter CriteriaEntry forlocation Box bounding box- Parameters:
boundingBox-GeoBoxbounding box(left top corner + right bottom corner)- Returns:
- this object
-
boundedBy
Adds a new filter CriteriaEntry for bounding box created from points- Parameters:
topLeftGeohash- left top corner of bounding box as geohashbottomRightGeohash- right bottom corner of bounding box as geohash- Returns:
- this object
-
boundedBy
Adds a new filter CriteriaEntry for bounding box created from points- Parameters:
topLeftPoint- left top corner of bounding boxbottomRightPoint- right bottom corner of bounding box- Returns:
- this object
-
boundedBy
Adds a new filter CriteriaEntry for bounding box created from points- Parameters:
topLeftPoint- left top corner of bounding boxbottomRightPoint- right bottom corner of bounding box- Returns:
- this object
-
within
Adds a new filter CriteriaEntry forlocation WITHIN distance -
within
Adds a new filter CriteriaEntry forlocation WITHIN distance -
within
Adds a new filter CriteriaEntry forgeoLocation WITHIN distance -
intersects
Adds a new filter CriteriaEntry for GEO_INTERSECTS.- Parameters:
geoShape- the GeoJson shape- Returns:
- this object
-
isDisjoint
Adds a new filter CriteriaEntry for GEO_IS_DISJOINT.- Parameters:
geoShape- the GeoJson shape- Returns:
- this object
-
within
Adds a new filter CriteriaEntry for GEO_WITHIN.- Parameters:
geoShape- the GeoJson shape- Returns:
- this object
-
contains
Adds a new filter CriteriaEntry for GEO_CONTAINS.- Parameters:
geoShape- the GeoJson shape- Returns:
- this object
-
hasChild
Adds a new filter CriteriaEntry for HAS_CHILD.- Parameters:
query- the has_child query.- Returns:
- the current Criteria.
-
hasParent
Adds a new filter CriteriaEntry for HAS_PARENT.- Parameters:
query- the has_parent query.- Returns:
- the current Criteria.
-
equals
-
hashCode
public int hashCode() -
toString
-