TSL (Tree Search Language) is a powerful, open-source query language developed by Yaacov Zamir that provides SQL-like filtering capabilities for structured data. This chapter is a pure language reference covering TSL syntax, operators, functions, and field access rules.
TSL is a query language with grammar similar to SQL’s WHERE clause. It parses human-readable filter expressions into an abstract syntax tree that can be evaluated against structured data such as JSON objects.
Key characteristics:
SQL-like syntax – familiar to anyone who has written SQL WHERE clauses
Type-aware – supports strings, numbers, booleans, dates, arrays, and null
Array-capable – first-class functions for working with array fields (len, any, all, sum)
SI unit literals – use Ki, Mi, Gi, Ti, Pi suffixes for byte quantities
Regex support – ~= and ~! operators for regular expression matching
Query Structure
A full TSL query follows this structure:
1
[SELECT fields] WHERE condition [ORDER BY field [ASC|DESC]] [LIMIT n]
The SELECT clause is optional. The most common form is:
1
where <condition> [order by <field> [asc|desc]] [limit <n>]
Clauses
Clause
Required
Description
SELECT
No
Select specific fields (rarely used in kubectl-mtv)
WHERE
Yes
Filter condition
ORDER BY
No
Sort by field, optionally ASC (default) or DESC
LIMIT
No
Maximum number of results to return
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
-- Filter onlywherename='web-01'-- Filter with sortingwherepowerState='poweredOn'orderbymemoryMBdesc-- Filter with sorting and limitwherememoryMB>1024orderbymemoryMBdesclimit10-- Select specific fields (reduces output size)selectname,memoryMB,cpuCountwherepowerState='poweredOn'limit10-- Full query: select, where, order by, limitselectname,memoryMBasmemwherememoryMB>4096orderbymemoryMBdesclimit5
Important: The in and not in operators require square brackets[...] for the value list, not parentheses.
Null Checking Operators
Operator
Description
Example
is null
Field is null
description is null
is not null
Field is not null
guestIP is not null
SELECT, ORDER BY, and LIMIT
SELECT Clause
The optional SELECT clause limits which fields are returned, reducing output size:
1
2
3
4
5
6
7
8
9
-- Select specific fieldsselectname,memoryMB,cpuCountwherepowerState='poweredOn'-- Field with alias (as)selectmemoryMBasmem,cpuCountascpuswherememoryMB>4096-- Reducers: sum, len, any, allselectname,sum(disks[*].capacityGB)astotalDiskwherepowerState='poweredOn'selectname,len(disks)asdiskCountwherelen(disks)>1
ORDER BY Clause
Sort results by field in ascending (default) or descending order:
1
2
3
4
5
6
7
8
9
10
11
-- Ascending (default)wherepowerState='poweredOn'orderbyname-- DescendingwherememoryMB>1024orderbymemoryMBdesc-- Multiple sort keyswherepowerState='poweredOn'orderbymemoryMBdesc,nameasc-- Order by aliasselectname,memoryMBasmemwherememoryMB>0orderbymemdesc
LIMIT Clause
Restrict the number of results returned:
1
2
3
4
5
6
7
8
-- Top 10wherepowerState='poweredOn'orderbymemoryMBdesclimit10-- First 50 alphabeticallywherepowerState='poweredOn'orderbynamelimit50-- Limit without order (first N matching)wherename~='prod-.*'limit5
Combined Examples (kubectl-mtv)
1
2
3
4
5
6
7
8
# Top 10 largest VMs by memory
kubectl mtv get inventory vms --provider vsphere-prod --query"where powerState = 'poweredOn' order by memoryMB desc limit 10"# Compact output: only name, memory, CPU
kubectl mtv get inventory vms --provider vsphere-prod --query"select name, memoryMB, cpuCount where powerState = 'poweredOn' limit 10"# Full query: select + where + order + limit
kubectl mtv get inventory vms --provider vsphere-prod --query"select name, memoryMB as mem where memoryMB > 4096 order by mem desc limit 5"
Functions
len(field)
Returns the length of an array or string. The comparison operator goes outside the parentheses:
QUERY STRUCTURE
[SELECT fields] WHERE condition [ORDER BY field [ASC|DESC]] [LIMIT n]
EXAMPLES
where name = 'vm1'
where memoryMB > 4096 order by memoryMB desc limit 10
select name, memoryMB where powerState = 'poweredOn' order by name limit 5
DATA TYPES
Strings 'single quoted'
Numbers 42, 3.14
SI Units Ki Mi Gi Ti Pi
Booleans true, false
Arrays ['a', 'b', 'c']
Null null
Dates '2024-01-01', '2024-01-01T00:00:00Z'
COMPARISONS = != <> < <= > >=
ARITHMETIC + - * / %
STRINGS like ilike ~= (regex) ~! (regex not)
LOGIC and or not ( )
SETS in [...] not in [...] between X and Y
NULLS is null is not null
FUNCTIONS
len(field) array/string length
any(cond) true if any element matches
all(cond) true if all elements match
sum(field) sum of numeric array values
FIELD ACCESS
field.sub dot notation
field[0] index access (zero-based)
field[*].sub wildcard (all elements)
field.sub implicit traversal (same as field[*].sub)
SORTING order by field [asc|desc]
LIMITING limit N
Built-in Help
Access the TSL reference directly from the command line: