> ## Documentation Index
> Fetch the complete documentation index at: https://docs.infrawatch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# InfraQL

> Search Infrawatch data with a typed, analyst-friendly query language

InfraQL is the query language for Infrawatch data. It combines readable search
syntax with typed fields, boolean logic, time windows, collections, pattern
matching, and dataset-aware correlation.

```text theme={null}
protocol:https AND port:443
```

The public API validates InfraQL against the selected dataset before it reaches
the search backend. Invalid fields, values, and operators return a stable
client error.

## What InfraQL supports

<CardGroup cols={2}>
  <Card title="Operators and values" icon="https://mintcdn.com/infrawatch/gCEz_Bv1hOrMPG8n/images/products/operators.svg?fit=max&auto=format&n=gCEz_Bv1hOrMPG8n&q=85&s=fd3224e0209386c46d60fd6c36f17909" href="/infraql/operators" width="32" height="32" data-path="images/products/operators.svg">
    Combine typed comparisons, boolean logic, collections, existence checks,
    and field aliases.
  </Card>

  <Card title="Time and ranges" icon="https://mintcdn.com/infrawatch/gCEz_Bv1hOrMPG8n/images/products/time.svg?fit=max&auto=format&n=gCEz_Bv1hOrMPG8n&q=85&s=d421eb1aaa8ff8f31c69b4cd3879a98e" href="/infraql/time" width="32" height="32" data-path="images/products/time.svg">
    Search relative windows, fixed dates, exact timestamps, and inclusive or
    exclusive ranges.
  </Card>

  <Card title="Correlate services" icon="https://mintcdn.com/infrawatch/gCEz_Bv1hOrMPG8n/images/products/correlation.svg?fit=max&auto=format&n=gCEz_Bv1hOrMPG8n&q=85&s=b42684cb60cccb048d9d37dce7024886" href="/infraql/correlation" width="32" height="32" data-path="images/products/correlation.svg">
    Use `same_service(...)` when several conditions must match one service on a
    host.
  </Card>

  <Card title="Patterns and text" icon="https://mintcdn.com/infrawatch/gCEz_Bv1hOrMPG8n/images/products/patterns.svg?fit=max&auto=format&n=gCEz_Bv1hOrMPG8n&q=85&s=b661b877508d488e1b94249f7752516a" href="/infraql/patterns" width="32" height="32" data-path="images/products/patterns.svg">
    Use contains, wildcards, regular expressions, quoted phrases, and bare
    banner terms where the field allows them.
  </Card>
</CardGroup>

## Choose a dataset

Search starts with the result you want:

| Dataset    | One result represents                  | Best for                                                       |
| ---------- | -------------------------------------- | -------------------------------------------------------------- |
| `hosts`    | An IP address with summarized services | Host context, exposure overviews, and infrastructure discovery |
| `services` | One observed network service           | Ports, protocols, banners, HTTP, TLS, and fingerprints         |
| `dns`      | One DNS observation segment            | Forward and reverse passive-DNS pivots                         |
| `osint`    | One intelligence report                | Published reporting associated with an IP or topic             |

<Note>
  Host queries normally prefix service fields with `services.`. Service queries
  use those fields directly. Inside `same_service(...)`, use the service field
  names without the prefix.
</Note>

## Start with a field

The basic clause is:

```text theme={null}
field:value
```

Combine clauses with `AND`, `OR`, `NOT`, and parentheses:

```text theme={null}
protocol:ssh AND (port:22 OR port:2222) AND NOT country_code:{US,CA}
```

InfraQL also accepts implicit `AND` between adjacent clauses:

```text theme={null}
protocol:ssh port:22
```

Use the explicit form in saved queries and automation because it is easier to
review.

## Examples by dataset

<Tabs>
  <Tab title="Hosts" icon="https://mintcdn.com/infrawatch/gCEz_Bv1hOrMPG8n/images/products/hosts.svg?fit=max&auto=format&n=gCEz_Bv1hOrMPG8n&q=85&s=0ba4d5739a3862f1d01e4ddc50c9dc3f" width="32" height="32" data-path="images/products/hosts.svg">
    ```text theme={null}
    same_service(protocol:ssh AND port:22) AND country_code:GB
    ```

    Returns hosts in Great Britain with one observed SSH service on port 22.
  </Tab>

  <Tab title="Services" icon="https://mintcdn.com/infrawatch/gCEz_Bv1hOrMPG8n/images/products/services.svg?fit=max&auto=format&n=gCEz_Bv1hOrMPG8n&q=85&s=ded195c4de499a693d3aa12d9f2a857c" width="32" height="32" data-path="images/products/services.svg">
    ```text theme={null}
    protocol:https AND timestamp>=now-24h
    ```

    Returns HTTPS endpoints observed during the last 24 hours.
  </Tab>

  <Tab title="DNS" icon="https://mintcdn.com/infrawatch/hFIgmGIh7O3VGQHG/images/products/dns.svg?fit=max&auto=format&n=hFIgmGIh7O3VGQHG&q=85&s=47a48af3a654f274eadb1754689f8dc4" width="32" height="32" data-path="images/products/dns.svg">
    ```text theme={null}
    answer_ip:1.1.1.1 AND first_seen>=now-30d
    ```

    Returns recent DNS observations whose answer is `1.1.1.1`.
  </Tab>

  <Tab title="OSINT" icon="https://mintcdn.com/infrawatch/hFIgmGIh7O3VGQHG/images/products/reports.svg?fit=max&auto=format&n=hFIgmGIh7O3VGQHG&q=85&s=3f8b076d5f975d979b40765807982f25" width="32" height="32" data-path="images/products/reports.svg">
    ```text theme={null}
    ip:1.1.1.1
    ```

    Returns published reports associated with `1.1.1.1`.
  </Tab>
</Tabs>

## Combine context in one query

Host search can combine network attribution, tag classifications, and evidence
from one matching service:

```text theme={null}
services.tags.category:proxy/*
AND country_code:DE
AND same_service(
  protocol:https
  AND http.title="Grafana"
)
```

This finds hosts in Germany that are classified in the proxy taxonomy and have
one HTTPS service whose page title equals `Grafana`. `same_service(...)`
prevents the protocol and HTTP conditions from matching different services on
the same host.

## Validate before execution

Validate a generated, user-supplied, or automated query against the same
dataset you intend to search:

```bash theme={null}
curl --request POST \
  --url "https://api.infrawatch.com/api/v1/search/hosts/validate" \
  --header "Content-Type: application/json" \
  --header "X-API-Key: ${INFRAWATCH_API_KEY}" \
  --data '{"query":"same_service(protocol:ssh AND port:22)"}'
```

Validation checks syntax, fields, operators, and dataset policy without running
the search.

## Run the search

Pass the InfraQL expression in `q`. `curl --data-urlencode` safely encodes
spaces and punctuation:

```bash theme={null}
curl --get "https://api.infrawatch.com/api/v1/search/services" \
  --header "X-API-Key: ${INFRAWATCH_API_KEY}" \
  --data-urlencode "q=protocol:ssh AND timestamp>=now-24h" \
  --data "limit=25"
```

Every response contains a dataset array, the normalized query, and a shared
pagination object.

<CardGroup cols={2}>
  <Card title="Browse every field" icon="https://mintcdn.com/infrawatch/gCEz_Bv1hOrMPG8n/images/products/data-dictionary.svg?fit=max&auto=format&n=gCEz_Bv1hOrMPG8n&q=85&s=7610d618bf3603732c6f9102b62101df" href="/data-dictionary" width="32" height="32" data-path="images/products/data-dictionary.svg">
    Inspect types, operators, aliases, and dataset-specific meanings.
  </Card>

  <Card title="Follow analyst workflows" icon="https://mintcdn.com/infrawatch/gCEz_Bv1hOrMPG8n/images/products/use-cases.svg?fit=max&auto=format&n=gCEz_Bv1hOrMPG8n&q=85&s=038f2239f51bdde5dd89ff8ef00d88e9" href="/use-cases" width="32" height="32" data-path="images/products/use-cases.svg">
    Apply InfraQL to IP, service, DNS, bulk-enrichment, and aggregation work.
  </Card>
</CardGroup>
