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

# クエリの構造

> Attack Surface Query の構成要素: バッチ、from、select、関連行、include、レスポンスの形

## バッチ

リクエストは、名前付きクエリの **バッチ** です。

```json theme={null}
{
  "window": { "since": "now-7d" },
  "queries": {
    "<name>": { "from": "<resource>", "...": "..." },
    "<another name>": { "from": "<resource>", "...": "..." }
  },
  "options": { "consistent": false, "mode": "interactive", "timezone": "UTC" }
}
```

**queries** `object` *required*

1～10 個の名前付きクエリ。名前は英字で始まり、英字、数字、`_` を含みます（最大 64 文字）。結果は同じ名前で返されます。

**window** `object`

独自のウィンドウを設定していないすべてのクエリのデフォルトの時間ウィンドウ: `{ "since": "now-7d", "until": "now" }`。[時間ウィンドウ](https://docs.oasm.io/ja/attack-surface-query/filtering.md#time-windows) を参照してください。

**options.consistent** `boolean` (default: false)

バッチのすべてのクエリを 1 つのデータベーススナップショット上で順番に実行します。複数のクエリの数値が正確に一致する必要がある場合（レポート）に使います。それ以外の場合、クエリは並列に実行されます。

**options.mode** `string` (default: interactive)

`interactive` はバッチをすぐに実行します。`report` は、はるかに大きな上限を持つバックグラウンドジョブとしてキューに入れます。[保存済みクエリとレポート](https://docs.oasm.io/ja/attack-surface-query/saved-queries-and-reports.md#report-mode) を参照してください。

**options.timezone** `string` (default: UTC)

時間バケット（`day`、`week` など）を区切る IANA タイムゾーン。例: `Asia/Ho_Chi_Minh`。[タイムゾーン](https://docs.oasm.io/ja/attack-surface-query/aggregations.md#time-zones) を参照してください。

> [!WARNING]
>
> すべてのオブジェクトは厳格です。どこかに未知のキー（`"selct"` のようなタイプミスや `workspaceId`）があると、無視されずにエラーになります。ワークスペースは常にセッションから取得され、ボディから取得されることはありません。

## クエリ

**from** `string` *required*

読み取るリソース: `targets`、`hosts`、`services`、`technologies`、`tls`、`urls`、`ips`、`dnsRecords`、`vulnerabilities`、`rollups`。

**select** `string[]`

返すフィールド。省略すると、小さなデフォルトのセットになります（`services` の場合: `port`、`host.value`、`firstSeen`）。

**include** `object`

各行に付加する関連行のリスト。[include](#include-lists-of-related-rows) を参照してください。

**where** `object`

フィルター。[フィルター](https://docs.oasm.io/ja/attack-surface-query/filtering.md) を参照してください。

**window** `object | null`

このクエリの時間ウィンドウ。バッチのものより優先されます。`null` は全期間を意味します。

**windowField** `string`

ウィンドウを適用する時間フィールド。デフォルト: リソースの `firstSeen`。

**groupBy / aggregate** `array / object`

クエリを集計に変えます。[集計とグループ化](https://docs.oasm.io/ja/attack-surface-query/aggregations.md) を参照してください。

**having** `object`

集計クエリのグループに対するフィルター。グループキーまたは集計名で指定します。[having](https://docs.oasm.io/ja/attack-surface-query/aggregations.md#having-filter-the-groups) を参照してください。

**fill** `boolean` (default: false)

空のものも含め、ウィンドウのすべての時間バケットを返します。[空のバケットを埋める](https://docs.oasm.io/ja/attack-surface-query/aggregations.md#filling-empty-buckets) を参照してください。

**orderBy** `object[]`

最大 3 つの `{ "field", "dir": "asc" | "desc" }`。デフォルト: 新しい順。

**limit** `number` (default: 50)

1 ページあたりの行数。最大値は [ページング、上限、コスト](https://docs.oasm.io/ja/attack-surface-query/paging-and-limits.md) を参照してください。

**cursor** `string`

前のページの `nextCursor`。

**withTotal** `boolean` (default: false)

一致する行の数 `total` も返します（上限は 10 000）。

## select: フィールドと関連行

フィールドは、リソースのフィールド（`port`）か、ドットパスで記述する **単一の関連行** のフィールドのいずれかです。サービスには 1 つのホスト、1 つのターゲット、1 つの最新の HTTP レスポンスがあるため、`services` では次のすべてが有効です。

```json theme={null}
{ "from": "services", "select": ["port", "host.value", "target.value", "http.title", "http.statusCode"] }
```

結果では関連フィールドがネストされます。

```json theme={null}
{
  "id": "53c80e50-…",
  "port": 443,
  "host": { "value": "api.example.com" },
  "target": { "value": "example.com" },
  "http": { "title": "API Gateway", "statusCode": 200 }
}
```

パスは 2 つの関連行をつなげられます。`technologies` → `service` → `host` で `service.host.value` になります。

> [!TIP]
>
> 存在しない関連行は、null の入ったオブジェクトではなく `null` として返されます。`"http": null` は、サービスに HTTP レスポンスがないことを意味します。

## include: 関連行のリスト

ホストには多くのサービスがあり、サービスには多くのテクノロジーと URL があります。リストは `select` には入れられないため、`include` で付加します。各 include はそれ自体が小さなクエリです。

```json theme={null}
{
  "from": "hosts",
  "select": ["value"],
  "limit": 20,
  "include": {
    "services": {
      "select": ["port", "http.title"],
      "limit": 10,
      "include": {
        "technologies": { "select": ["name", "version"], "limit": 5 }
      }
    }
  }
}
```

```json theme={null}
{
  "id": "1396ad91-…",
  "value": "api.example.com",
  "services": [
    { "id": "…", "port": 443, "http": { "title": "API Gateway" },
      "technologies": [ { "id": "…", "name": "nginx", "version": "1.25" } ] }
  ]
}
```

**include.\<list>.select** `string[]`

子の行（とその関連行）のフィールド。

**include.\<list>.where** `object`

子の行に対するフィルター。一致する子だけが付加されます。親の行はこれではフィルターされません（そのためには親の `where` を使います）。

**include.\<list>.orderBy** `object[]`

子の順序。リストを並べ替えられるのは一部のフィールドだけです（たとえば `firstSeen`、ホストのサービスでは `port`）。それ以外は自然な順序のままです。

**include.\<list>.limit** `number` (default: 10)

親の行 1 つあたりの子の数（最大 50。AI エージェントでは 20）。

**include.\<list>.include** `object`

ネストしたリスト。最大 2 階層までです。

> [!WARNING]
>
> 各 include は、**すべての行について** それぞれの上限まで取得します。200 ホスト × 20 サービスは 4 000 行の子になります。`limit × include の limit` は小さく保つか、フィルター付きで子のリソースを直接クエリしてください（[クエリを組み立てる](https://docs.oasm.io/ja/attack-surface-query/composing-queries.md) を参照）。

### 各リソースのリスト

| リソース | 単一の関連行（ドット付きの `select`） | リスト（`include` または `where`） |
| - | - | - |
| `targets` | – | `hosts` |
| `hosts` | `target` | `services`、`ips`、`dnsRecords`、`vulnerabilities` |
| `services` | `host`、`target`、`http` | `technologies`、`tls`、`statusCodes`、`urls`、`tags` |
| `technologies`、`tls`、`urls` | `service` | – |
| `ips`、`dnsRecords` | `host` | – |
| `vulnerabilities` | `host`、`tool` | – |

## デフォルトのフィールドと順序

| リソース | デフォルトの `select` | デフォルトの順序 |
| - | - | - |
| `targets` | `value`、`type`、`firstSeen` | 新しい順 |
| `hosts` | `value`、`kind`、`firstSeen`、`target.value` | 新しい順 |
| `services` | `port`、`host.value`、`firstSeen` | 新しい順 |
| `technologies` | `name`、`version`、`service.host.value`、`service.port` | 新しい順 |
| `tls` | `host`、`port`、`notAfter`、`issuerCn` | `notAfter` の昇順（期限が近い順） |
| `urls` | `url`、`firstSeen` | 新しい順 |
| `ips` | `ip`、`host.value` | 新しい順 |
| `dnsRecords` | `recordType`、`value`、`host.value` | 新しい順 |
| `vulnerabilities` | `name`、`severity`、`host.value`、`firstSeen` | 新しい順 |
| `rollups` | `metric`、`key`、`value` | `value` の降順 |

読み取りを許可されていないデフォルトのフィールド（たとえば `target.read` がない場合の `target.value`）は、クエリを失敗させずに除外されます。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.