Search > Search API

DSL (Domain Specific Language) search API (Experimental)

DSL(Domain Specific Language) Syntax

DSL query comprises of entity type and optional predicate to help filter the given entity type based on its properties.

DSL syntax has the following structure:

EntityType WHERE Predicate

Where Predicate stands for PropertyName RelationalOperator PropertyValue

See example:

LogicalSwitch where admin_state = down

Multiple Predicates can be combined using the Logical Operators.

DSL query is case insensitive.

Entity Type

We can search for any entity type by specifying it in the DSL query.

To find all segments use simple DSL query as:

segment

Predicate

Predicate helps define the search criteria for the specified entity type.

To search rules with action rejected, use DSL query as:

rule where action = reject

To search virtual machine which has power state running, use DSL query as :

VirtualMachine where power_state = "VM_RUNNING"

Nested properties can be search for using the "." (dot notation) like "tags.scope".

To search groups with tag scope as production, use DSL query as:

Group where tags.scope = production

Relational Operator

The comparison operators =, !=, <, <=, >, >=, like can be used to match property values.

Operator Type Note
<, <=, >, >= Numeric Operators <, <=, > and >= can be used for numeric properties.
=, != Numeric, String, Boolean Used for numeric, text and boolean properties.
like String Used to find entities where "property_name" contains "value".

To search for Tier1 Gateways which have display name Test, use DSL query as:

tier1 where display_name = Test

To search for virtual machines which have display name like App-VM, use DSL query as:

VirtualMachine where display_name like App-VM

To search for logical switches which have vni between 65538 and 65553, use DSL query as:

LogicalSwitch where vni > 65538 and vni < 65553

Logical Operator

Logical operator "AND" and "OR" can be use to combine two predicates. We can use parentheses "(" and ")" to define nested logical operations.

To search for Tier0 Gateways where Failover Mode is Non Preemptive or HA Mode is Active-Active and Firewall is disabled, we can use the query:

tier0 where failover mode = non_preemptive or (ha mode = active_active and disable firewall = true)

Searchable types+

Request:

Method:
GET
URI Path(s):
/api/v1/search/dsl
Request Headers:
n/a
Query Parameters:
SearchQueryRequest+
Request Body:
n/a

Example Request:

GET https://<nsx-mgr>/api/v1/search/dsl?query=group%20where%20tags%20scope%20%3D%20%27prod%27 GET https://<nsx-mgr>/policy/api/v1/search/dsl?query=group%20where%20tags%20scope%20%3D%20%27prod%27 GET https://<nsx-mgr>/global-manager/api/v1/search/dsl?query=group%20where%20tags%20scope%20%3D%20%27prod%27

Successful Response:

Response Code:
200 OK
Response Headers:
Content-type: application/json
Response Body:
SearchResponse+

Example Response:

{ "results": [ { "_last_modified_user": "admin", "_revision": 4, "_system_owned": false, "resource_type": "Group", "description": "Prod Env Group", "_protection": "NOT_PROTECTED", "_last_modified_time": 1561700732921, "display_name": "ProdEnvGroup", "_create_user": "admin", "tags": [ { "scope": "Prod", "tag": "Group" } ], "_create_time": 1561614698915, "path": "/infra/domains/default/groups/4fc8c310-989f-11e9-baf3-930b233a84c6", "marked_for_delete": false, "parent_path": "/infra/domains/default", "id": "4fc8c310-989f-11e9-baf3-930b233a84c6", "relative_path": "4fc8c310-989f-11e9-baf3-930b233a84c6", "status": { "consolidated_status_per_enforcement_point": [ { "consolidated_status": { "consolidated_status": "SUCCESS" }, "enforcement_point_id": "default" } ], "consolidated_status": { "consolidated_status": "SUCCESS" }, "intent_path": "/infra/domains/default/groups/4fc8c310-989f-11e9-baf3-930b233a84c6" } } ], "result_count": 1, "cursor": "1" }

Required Permissions:

read

Feature:

search

Additional Errors: