/ #code 

Create Complex Search Queries using the NSX-T Search API

The NSX-T search function is compelling: you can search for objects using various criteria throughout the NSX-T inventory. You can not only just type something to query (a name, a UUID, etc.) and you will get all relevant results, but also create queries using a search pattern.

NSX-T search function in the user interface

The search results are sorted by relevance, and you can filter these results based on your search query. The search function helps with auto-completion and suggestions: in the example above, it provides me a list of tags from which I can choose.

Another example below: I want to list all Tier-1 gateways with the word terraform in the description.

NSX-T search function: search for all tier-1 gateways with a specific description

Now, that’s in the UI: it’s great, but what if you need to get some information hidden in the UI on objects that could only be found using a search query? I had recently to look for specific NSX-T objects ID (for a PowerShell function) and I was struggling on how to construct my query.

Fortunately, Thomas Vigneron (NSBU PM) had the answer! While the search feature was always available in the UI, NSX-T 3.0 added the search API GET /policy/api/v1/search/query which allows to do a full-text search API request.

To get the same result as my first example above, I use the following request: GET /policy/api/v1/search?query=resource_type:(PolicyNatRule) AND (tags.tag:"urn:vcloud:org:63035a23-560f-484b-90fc-c691778b6d10").

NSX-T Search API: full-text search API request

The search API supports a wide list of resource types you can search on, as well as wildcards and boolean operators (AND, OR, NOT).

Check for the complete description and documentation in the NSX-T Data Center Rest API Guide.

Author

Romain

Staff Technical Product Manager, technologist with 16+ years of Networking and Security experience in Data Center, Public Cloud & Virtualization (VMs and Containers). He is a double VCDX (DCV and NV, #120), VCDX panelist, frequent VMUG/VMworld speaker and contributor to the community via this blog or social media (follow him on Twitter @woueb).