When you perform an entityQuery you can filter the response based on the value of fields using the
When building the QueryFilter
object you provide a field
name (which must be a field on the entityType
you are looking for) on which to filter. The operator
field is an ENUM with the below values that can be used when creating a filter:
EQ
equal toNEQ
not equal toLT
less thanLTE
less than or equal toGT
greater thanGTE
greater than or equal toCONTAINS
case sensitive check for the provided string within the field valueSTARTSWITH
case sensitive check if the field value starts with the provided stringENDSWITH
case sensitive check if the field value ends with the provided stringISNULL
field is nullISNOTNULL
field is not nullThe value
is provided for the comparison operators, except the ISNULL
and ISNOTNULL
operators.
A basic example of filtering is to look for any AWS EC2 instances and Azure Virtual Machines that are tagged with Name=VM 1
. The query below uses the field tag.Name
(the dot notation allows you to access nested field names) and the operator EQ
, and looks for the value VM 1
. Note that the values field is an array, so it can hold multiple values.
|
|
The query below uses the field tag.Name
and the operator ISNOTNULL
to filter AWS EC2 instances and Azure Virtual Machines that have a Name
tag.
|
|
The QueryFilter
object also supports and
, or
and not
logical operators to use multiple filters or to negate a filter, for example the query below will return AWS EC2 instances and Azure Virtual Machines that are tagged with Name=VM 1
, Name=VM2
OR Tier=Web
. When using and
, or
, or not
the value must be an array of QueryFilter
objects.
If the below query were to be changed to an and
operator, the query would return AWS EC2 instances and Azure Virtual Machines that are tagged with either Name=VM 1
, Name=VM2
AND Tier=Web
|
|