Using Filters
The ODIN CLI allows users to filter data using a flexible and powerful filter syntax. This is especially useful when working with large datasets, allowing you to extract exactly the information you need.
Basics
You can set a filter using the --filter flag followed by the filter expression. If omitted, the command will return
all resources. Resources are filtered on the server side, but depending on command it may also be filtered on the client
side or even a combination of both.
The filter expression follows a straightforward structure of <field> <operator> <value>. The field can be any property
in the dataset, and operators include basic comparison operators such as =, !=, >, <, >=, and <=. Filters
can also be combined using logical operators AND, OR, and negated with NOT.
You can access nested fields using dot notation, and strings should be enclosed in quotes. Here’s an example using a basic filter:
This filter will return all servers where the serverConfig.name is "Minecraft Production 2".
Supported Operators
=: Equal to!=: Not equal to>: Greater than<: Less than>=: Greater than or equal to<=: Less than or equal to~: Contains (for strings)
The ~ also allows usage of wildcards (*) for partial matches. For example:
This filter will return all servers where the serverConfig.name starts with "Minecraft".
Combining Filters
You can combine multiple conditions using AND and OR operators:
AND: Both conditions must be true.OR: At least one condition must be true.
This filter will return all servers where the serverConfig.name is "Minecraft Production 2" and the id is greater
than 100.
Negation with NOT
You can negate conditions using the NOT operator. For example:
This will return all servers where the serverConfig.name is not "Minecraft Production 2".
Accessing Nested Properties
You can filter based on nested properties using dot notation. For example, if you want to filter servers based on a
nested property like serverConfig.name, you can do:
Here’s an example using the serverConfig object from a typical server JSON structure (just the interesting part is
shown here):
This filter will return all servers with the serverConfig.name set to "Minecraft Production 2".
Examples
Filtering Servers by Config
This filter will return servers that are ready and have the name "Minecraft Production 2".
Combining Logical Conditions
This will return servers that either:
- Have a
serverConfig.statusof"ready"and aserverConfig.nameof"Minecraft Production 2", or - Have an
idof211.
Negating Conditions
This filter will return all servers where the serverConfig.status is not "ready".
Filtering by Ports
If you need to filter based on the ports object in the server JSON, you can do so using nested access. For example, to
filter by the publishedPort in Game Port:
This will return servers where the published game port is 30097.
Practical Use Cases
Filtering for Inactive Servers
You can quickly filter for servers that are not running:
This returns all servers whose status.state is not running.
Filtering by Location
If you need to filter servers based on their location, you can access the location object:
This will return all servers located in the city of Limburg, Germany.
Advanced Filters
You can also create more complex filter expressions that combine multiple conditions:
This filter will return servers with either the name "Minecraft Production 2" or "ODIN Fleet" that are located in
Germany.