CLIを使用してクエリを実行し、結果を出力できます。以下の手順では、CLIを使用してクエリ出力結果をフォーマットする方法を説明します。
このトピックには以下が含まれます:
単一のクエリの結果をElastic Cloudに出力するには、td queryコマンドに--resultオプションを追加します。ジョブが完了すると、結果はデータベースに書き込まれます:
- Nodes: ノードのカンマ区切りリスト
- Use SSL? SSLを使用するかどうか
- Auth Method: BasicまたはNoneのいずれかを選択
- Username: Basic認証のユーザー名
- Password: 上記ユーザーのパスワード
- Mode: insertまたはreplaceのいずれかを選択
- Index: インデックスの名前
- Type: typeの名前
- ID: (オプション) IDカラムの名前
Elastic Cloud用のTD queryコマンドフォーマットの例:
td query \
--result '{"type":"elasticcloud","mode":"insert","nodes":[{"host":"host","port":port}],
"use_ssl":true,"auth_method":"basic","user":"user",
"index":"index","index_type":"log","bulk_actions":1000,
"bulk_size":5242880,"fill_null_for_empty_column":true,
"maximum_retries":7,"maximum_retry_interval_millis":120000}'-w \
-d ivan_test_td \
"SELECT column_name, COUNT(1) FROM table GROUP BY column"出力を体系的にElastic Cloudに書き込むスケジュールクエリを作成するには、td sched:createコマンドでスケジュールを作成する際に--resultオプションを追加します。ジョブが実行されるたびに、結果はmytblに書き込まれます。
td result:create mydb elascloud://user:password@host/database
td sched:create hourly_count_example "0 * * * *" \
-d testdb \
"select count(*) from www_access" \
--result mydb:mytbl結果出力ターゲットは、以下のフォーマットのURLで表されます:
{
"type":"elasticcloud",
"mode":"mode",
"nodes":[
{
"host":"host",
"port":"port"
}
],
"auth_method":"none",
"index":"index",
"index_type":"dump",
"bulk_actions":1000,
"bulk_size":5242880
}パラメータの説明:
- host: ホスト名
- port: ポート番号
- modes: appendまたはreplaceを指定