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 nameprotected
Creates a Criteria for the given field, sets it's criteriaChain to the given value and adds itself to the end of the chain.protected
Creates 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 Criteria
and()
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 box
Adds a new filter CriteriaEntry for bounding box created from pointsAdds a new filter CriteriaEntry forlocation Box bounding box
Adds a new filter CriteriaEntry for bounding box created from pointsAdd aCriteria.OperationKey.CONTAINS
entry 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.EMPTY
entry to thequeryCriteriaEntries
.Add aCriteria.OperationKey.ENDS_WITH
entry to thequeryCriteriaEntries
NOTE: mind your schema as leading wildcards may not be supported and/or execution might be slow.boolean
exists()
Add aCriteria.OperationKey.EXISTS
entry to thequeryCriteriaEntries
expression
(String s) Add aCriteria.OperationKey.EXPRESSION
entry to thequeryCriteriaEntries
allowing native elasticsearch expressionsAdd aCriteria.OperationKey.FUZZY
entry to thequeryCriteriaEntries
float
getBoost()
getField()
greaterThan
(Object lowerBound) Add aCriteria.OperationKey.GREATER
entry to thequeryCriteriaEntries
greaterThanEqual
(Object lowerBound) Add aCriteria.OperationKey.GREATER_EQUAL
entry to thequeryCriteriaEntries
int
hashCode()
Add aCriteria.OperationKey.IN
entry to thequeryCriteriaEntries
.Add aCriteria.OperationKey.IN
entry to thequeryCriteriaEntries
.intersects
(GeoJson<?> geoShape) Adds a new filter CriteriaEntry for GEO_INTERSECTS.Add aCriteria.OperationKey.EQUALS
entry to thequeryCriteriaEntries
boolean
isAnd()
isDisjoint
(GeoJson<?> geoShape) Adds a new filter CriteriaEntry for GEO_IS_DISJOINT.boolean
boolean
isOr()
Add aCriteria.OperationKey.LESS
entry to thequeryCriteriaEntries
lessThanEqual
(Object upperBound) Add aCriteria.OperationKey.LESS_EQUAL
entry to thequeryCriteriaEntries
Add aCriteria.OperationKey.MATCHES
entry to thequeryCriteriaEntries
.matchesAll
(Object value) Add aCriteria.OperationKey.MATCHES
entry to thequeryCriteriaEntries
.not()
Sets the negating flagnotEmpty()
Add aCriteria.OperationKey.NOT_EMPTY
entry to thequeryCriteriaEntries
.Add aCriteria.OperationKey.NOT_IN
entry to thequeryCriteriaEntries
.Add aCriteria.OperationKey.NOT_IN
entry to thequeryCriteriaEntries
.static Criteria
or()
Chain a new or-CriteriaChain a new or-Criteria.Chain a new or-CriteriaAdd aCriteria.OperationKey.REGEXP
entry to thequeryCriteriaEntries
.startsWith
(String s) Add aCriteria.OperationKey.STARTS_WITH
entry to thequeryCriteriaEntries
subCriteria
(Criteria criteria) adds a Criteria as subCriteriatoString()
static Criteria
Static factory method to create a new Criteria for field with given namestatic Criteria
Static factory method to create a new Criteria for provided fieldAdds a new filter CriteriaEntry forgeoLocation WITHIN distance
Adds a new filter CriteriaEntry for GEO_WITHIN.Adds a new filter CriteriaEntry forlocation WITHIN distance
Adds 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.EQUALS
entry to thequeryCriteriaEntries
- Parameters:
o
- the argument to the operation- Returns:
- this object
-
exists
Add aCriteria.OperationKey.EXISTS
entry 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_WITH
entry to thequeryCriteriaEntries
- Parameters:
s
- the argument to the operation- Returns:
- this object
-
contains
Add aCriteria.OperationKey.CONTAINS
entry 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_WITH
entry 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.IN
entry 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_IN
entry to thequeryCriteriaEntries
. See the comment atin(Object...)
.- Parameters:
values
- the argument to the operation- Returns:
- this object
-
notIn
Add aCriteria.OperationKey.NOT_IN
entry to thequeryCriteriaEntries
. See the comment atin(Object...)
.- Parameters:
values
- the argument to the operation- Returns:
- this object
-
expression
Add aCriteria.OperationKey.EXPRESSION
entry to thequeryCriteriaEntries
allowing native elasticsearch expressions- Parameters:
s
- the argument to the operation- Returns:
- this object
-
fuzzy
Add aCriteria.OperationKey.FUZZY
entry to thequeryCriteriaEntries
- Parameters:
s
- the argument to the operation- Returns:
- this object
-
lessThanEqual
Add aCriteria.OperationKey.LESS_EQUAL
entry to thequeryCriteriaEntries
- Parameters:
upperBound
- the argument to the operation- Returns:
- this object
-
lessThan
Add aCriteria.OperationKey.LESS
entry to thequeryCriteriaEntries
- Parameters:
upperBound
- the argument to the operation- Returns:
- this object
-
greaterThanEqual
Add aCriteria.OperationKey.GREATER_EQUAL
entry to thequeryCriteriaEntries
- Parameters:
lowerBound
- the argument to the operation- Returns:
- this object
-
greaterThan
Add aCriteria.OperationKey.GREATER
entry to thequeryCriteriaEntries
- Parameters:
lowerBound
- the argument to the operation- Returns:
- this object
-
matches
Add aCriteria.OperationKey.MATCHES
entry 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.MATCHES
entry 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.EMPTY
entry to thequeryCriteriaEntries
.- Returns:
- this object
- Since:
- 4.3
-
notEmpty
Add aCriteria.OperationKey.NOT_EMPTY
entry to thequeryCriteriaEntries
.- Returns:
- this object
- Since:
- 4.3
-
regexp
Add aCriteria.OperationKey.REGEXP
entry 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
-GeoBox
bounding box(left top corner + right bottom corner)- Returns:
- this object
-
boundedBy
Adds a new filter CriteriaEntry forlocation Box bounding box
- Parameters:
boundingBox
-GeoBox
bounding 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
-
equals
-
hashCode
public int hashCode() -
toString
-