Nested Queries

Best Practices

Follow these practices to write nested queries that return the results you expect.

Group Tokens That Share a Key

Use nested queries when multiple tokens share a common key. A nested query groups related conditions under the same key, so that all criteria are evaluated together.

For example, in the following query, both tokens share the asset key, so they are enclosed in a single nested query:

asset:(assetID:43954857 AND cpuCount:2)

The query finds the asset that has both the specified assetID and cpuCount values.

Child Tokens in Nested Queries

Use separate nested queries when filtering assets based on multiple values of the same child token.

When querying nested fields, you cannot use the same child token more than once within a single nested query. Instead, create a separate nested query for each value and combine the conditions using the and operator.

Example

To find assets associated with both Passive Sensor and IP Scanner sources, use the following query:

asset.inventory:(source:`Passive Sensor`) and asset.inventory:(source:`IP Scanner`)

The following query is invalid because it uses the source child token twice within the same nested query:

asset.inventory:(source:`Passive Sensor` and source:`IP Scanner`)

 

Query Examples

The results depend on the intent of your query, as shown in the following examples:

Query Description Result
asset:(agentID:123456789 AND lastLoggedOnUser:jrbilles) Looks for findings where both the agent ID and the last logged-on user match for the same asset. A finding is returned only if both criteria are true for the same asset.
asset.agentID:123456789 AND lastLoggedOnUser:jrbilles Looks for findings with the agent ID or the last logged-on user. The conditions are not grouped under the same key, so each is checked separately. Findings that match either or both conditions.
software:(name:DataRobot AND version:2.0) Looks for assets that have software with both the specified name and version. An asset is returned only if both software attributes match.
software:(name:DataRobot) AND software:(version:1.0) Looks for assets that have the software name and assets that have the software version. Each condition is checked separately. All assets that have the software name, and all assets that have the software version.
software:(name:DataRobot OR version:1.0) Looks for assets that have either the software name or the software version. All assets that match at least one of the conditions.

When conditions are not grouped under the same key, each condition is evaluated separately. As a result, your search may return more results than you expect.

Related Topics

How to Search in CSAM

Boolean Queries