Use lookups in a search
A lookup file is a small table of reference data, such as a list of critical hosts and their owners. In Search you can read it as a source, or use it to add columns to events.
Role needed: Search: Read to query a lookup file. Creating, changing and deleting lookup files needs Settings access with Correlations: Set (Correlations: Delete to delete one).
Find the name to query
Each lookup file has a query name that starts with lookup_. It is the file's name in lower case, with every run of characters other than letters and digits replaced by one underscore. A file called Critical Systems is queried as lookup_critical_systems. The name is fixed when the file is created, so renaming the file later does not break saved queries.
- Select Settings in the top bar, then Lookup Files in the Enrichment & Context group.
- Find the file. The Query as column shows its query name. Select the copy button, Copy alias, to copy it.
The Search mirror column shows whether Search can read the file: ready, pending or error. A file that is pending or in error may not be queryable, or may not yet match what you see in Settings. A file in error is left out of the editor's suggestions and is retried automatically; select the retry button beside it to try again at once.
Query a lookup file
Use the query name as the source.
source=lookup_critical_systems
Search shows the file's rows. A lookup file has no time column, so the time range does not apply to it, and there is no histogram.
Add columns to events
Accounts that are not Admin or Super Admin can use lookup only with a lookup file (a name starting lookup_).
Use the lookup command to match events against the file and add its columns.
source=log_* | lookup lookup_critical_systems hostname as host.hostname output owner, priority
| Part | Meaning |
|---|---|
lookup_critical_systems | The lookup file. |
hostname as host.hostname | The column in the file to match, and the event field it must equal. |
output owner, priority | The columns to add to each event. They replace a field of the same name. Use append instead of output to fill a field only when the event has no value for it. |
Matching compares text, so a value must be written the same way in the file and in the event. Events that match nothing are kept, with empty added columns. To keep only the matches, add a stage after the lookup:
source=log_* | lookup lookup_critical_systems hostname as host.hostname output owner, priority | where isnotnull(owner)
As you type, the editor suggests lookup files after source= and lookup, the file's columns after the match column, the event fields after as, and the file's columns again after output and append.
You can use an added column like any other field, for example ... | stats count() as events by owner.
Create a lookup file
You can create a file in Settings or from search results.
From Settings
- Select Settings, then Lookup Files.
- Select the plus button (New lookup file).
- Enter a Name and, optionally, a Description.
- Under Source, choose Upload CSV/JSON and select a file, or choose Create manually and enter the column names, separated by commas, then add rows afterwards.
- Select Create.
A CSV file needs a header row. A JSON file must be an array of objects, one per row. The file must be under about 680 KB and hold at most 5,000 rows. Once parsed, the table must also stay under about 880 KB, so a file with many columns can be refused even when it is under 680 KB. Names must be unique, and a name must contain at least one letter or number. Column names must not be empty or repeated (case does not matter), and must not contain round brackets or backticks. All values are stored as text.
From search results
- Run a query that returns the rows you want, with named columns. Name each aggregate with
as, because a column name such ascount()contains round brackets and is refused. For example,stats count() as events by host.hostname. - Select Save, then Lookup File.
- Enter a Name, and optionally a Description, and select Save.
The new file holds the rows currently loaded in the results, which is the current page for a list of events, and one column for each field in the rows. The panel shows the number of rows it will save. Check it before you save.
Next steps
- ThreatVIS PPL examples: a query that uses a lookup file.
- Detection content: where lookup files and Reference Lists are managed for Detection Rules.