Azure Data Explorer は、アプリケーション、Web サイト、IoT デバイスなどからの大量のデータ ストリーミングをリアルタイムに分析するための高速でフル マネージドのデータ分析サービスです。 Azure Data Explorer を使用するには、最初にクラスターを作成し、そのクラスター内に 1 つまたは複数のデータベースを作成します。 その後、データをデータベースに取り込み (読み込み)、データに対してクエリを実行できます。
この記事では、C#、Python、Go、Azure CLI、PowerShell、Bicep、または Azure Resource Manager (ARM) テンプレートを使用してクラスターとデータベースを作成する方法について説明します。 Azure portal を使用してクラスターとデータベースを作成する方法を確認するには、「クイック スタート: Azure Data Explorer クラスターとデータベースを作成する」を参照してください。
以前の SDK バージョンに基づくコード サンプルについては、アーカイブ記事を参照してください。
前提条件
クラスターとデータベースの作成方法別の前提条件:
Important
Azure CLIの Kusto 拡張機能は古く、管理されていません。 クラスターとデータベースの作成には、PowerShell または ARM/Bicep テンプレートを使用することをお勧めします。 Azure CLIを使用する場合は、Kusto 拡張機能をインストールして、Azure Data Explorer用の最新の CLI コマンドがあることを確認してください。
Azure Cloud Shell でコマンドを実行している場合、次の手順は必要ありません。 CLI をローカルで実行している場合は、次の手順に従って環境を設定します。
最新の Kusto CLI バージョンを使用する拡張機能をインストールします。
az extension add -n kusto
次のコマンドを実行して、Azure にサインインします。
az login
クラスターを作成するサブスクリプションを設定します。
MyAzureSub は、使用する Azure サブスクリプションの名前に置き換えてください。
az account set --subscription MyAzureSub
クラスターを作成するリソース グループを設定します。
testrg は、使用するリソース グループの名前に置き換えます。
az group create --name testrg --location westus
Azure Data Explorer クラスターを作成します
このセクションでは、Azure Data Explorer クラスターを作成するプロセスについて説明します。 クラスターを作成するために推奨される方法に関連するタブを選択します。
ARM テンプレート
以下は、最小限の構成でAzure Data Explorerクラスターとそのクラスター内にデータベースを作成する ARM テンプレートの例です。 詳細とサポートされるプロパティについては、 ARM テンプレート クラスターリファレンス と ARM テンプレート データベース リファレンスを参照してください。
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusters_kustocluster_name": {
"type": "string",
"defaultValue": "[concat('kusto', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Name of the cluster to create"
}
},
"databases_kustodb_name": {
"type": "string",
"defaultValue": "kustodb",
"metadata": {
"description": "Name of the database to create"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {},
"resources": [
{
"name": "[parameters('clusters_kustocluster_name')]",
"type": "Microsoft.Kusto/clusters",
"apiVersion": "2025-02-14",
"location": "[parameters('location')]",
"sku": {
"name": "Standard_E8ads_v5",
"tier": "Standard",
"capacity": 2
}
},
{
"name": "[concat(parameters('clusters_kustocluster_name'), '/', parameters('databases_kustodb_name'))]",
"type": "Microsoft.Kusto/clusters/databases",
"apiVersion": "2025-02-14",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Kusto/clusters', parameters('clusters_kustocluster_name'))]"
],
"kind": "ReadWrite",
"properties": {
"softDeletePeriod": "P365D",
"hotCachePeriod": "P31D"
}
}
]
}
最小構成でAzure Data Explorer クラスターとそのクラスター内にデータベースを作成するBicep テンプレートの例を次に示します。 詳細とサポートされるプロパティについては、Bicep クラスターリファレンスおよびBicepデータベース リファレンスを参照してください。
@description('Name of the cluster to create')
param clusterName string = 'kusto${uniqueString(resourceGroup().id)}'
@description('Name of the database to create')
param databaseName string = 'kustodb'
@description('Location for all resources.')
param location string = resourceGroup().location
resource cluster 'Microsoft.Kusto/clusters@2025-02-14' = {
name: clusterName
location: location
sku: {
name: 'Standard_E8ads_v5'
tier: 'Standard'
capacity: 2
}
}
resource database 'Microsoft.Kusto/clusters/databases@2025-02-14' = {
parent: cluster
name: databaseName
location: location
kind: 'ReadWrite'
properties: {
softDeletePeriod: 'P365D'
hotCachePeriod: 'P31D'
}
}
次のコマンドを使用して、クラスターを作成します。
New-AzKustoCluster -ResourceGroupName testrg -Name mykustocluster -Location westus2 -SkuTier Standard -SkuCapacity 2 -SkuName 'Standard_E8ads_v5'
|
設定 |
推奨値 |
フィールドの説明 |
| 名前 |
mykustocluster |
クラスターの任意の名前。 |
| Sku |
Standard_E8ads_v5 |
クラスターに使用される SKU。 |
| ResourceGroupName |
testrg |
クラスターが作成されるリソース グループの名前。 |
使用できるその他の省略可能なパラメーターが存在します (クラスターの容量など)。
クラスターが正常に作成されたかどうかを確認するには、次のコマンドを実行します。
Get-AzKustoCluster -Name mykustocluster -ResourceGroupName testrg
結果に provisioningState が Succeeded として含まれていることを確認して、クラスターの正常な作成を確認します。
次のコードを使用してクラスターを作成します。
var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Directory (tenant) ID
var clientId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Application ID
var clientSecret = "PlaceholderClientSecret"; //Client Secret
var subscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
var credentials = new ClientSecretCredential(tenantId, clientId, clientSecret);
var resourceManagementClient = new ArmClient(credentials, subscriptionId);
var resourceGroupName = "testrg";
var subscription = await resourceManagementClient.GetDefaultSubscriptionAsync();
var resourceGroup = (await subscription.GetResourceGroupAsync(resourceGroupName)).Value;
var clusters = resourceGroup.GetKustoClusters();
var clusterName = "mykustocluster";
var skuName = KustoSkuName.StandardE8adsV5;
var skuTier = KustoSkuTier.Standard;
var capacity = 5;
var clusterData = new KustoClusterData(
location: AzureLocation.CentralUS,
sku: new KustoSku(skuName, skuTier) { Capacity = capacity }
);
await clusters.CreateOrUpdateAsync(WaitUntil.Completed, clusterName, clusterData);
|
設定 |
推奨値 |
フィールドの説明 |
| clusterName |
mykustocluster |
クラスターの任意の名前。 |
| skuName |
Standard_E8ads_v5 |
クラスターに使用される SKU。 |
| レベル |
Standard |
SKU レベル。 |
| キャパシティ |
番号 |
クラスターのインスタンスの数。 |
| resourceGroupName |
testrg |
クラスターが作成されるリソース グループの名前。 |
注
クラスターの作成 は長時間実行される動作であるため、CreateOrUpdate の代わりに CreateOrUpdateAsync を使用することを強くお勧めします。
クラスターが正常に作成されたかどうかを確認するには、次のコマンドを実行します。
clusterData = (await clusters.GetAsync(clusterName)).Value.Data;
結果に provisioningState が Succeeded として含まれていることを確認して、クラスターの正常な作成を確認します。
次のコマンドを使用して、クラスターを作成します。
from azure.mgmt.kusto import KustoManagementClient
from azure.mgmt.kusto.models import Cluster, AzureSku
from azure.common.credentials import ServicePrincipalCredentials
#Directory (tenant) ID
tenant_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
#Application ID
client_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
#Client Secret
client_secret = "xxxxxxxxxxxxxx"
subscription_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
credentials = ServicePrincipalCredentials(
client_id=client_id,
secret=client_secret,
tenant=tenant_id
)
location = 'Central US'
sku_name = 'Standard_E8ads_v5'
capacity = 5
tier = "Standard"
resource_group_name = 'testrg'
cluster_name = 'mykustocluster'
cluster = Cluster(location=location, sku=AzureSku(name=sku_name, capacity=capacity, tier=tier))
kusto_management_client = KustoManagementClient(credentials, subscription_id)
cluster_operations = kusto_management_client.clusters
poller = cluster_operations.begin_create_or_update(resource_group_name, cluster_name, cluster)
poller.wait()
|
設定 |
推奨値 |
フィールドの説明 |
| cluster_name |
mykustocluster |
クラスターの任意の名前。 |
| sku_name |
Standard_E8ads_v5 |
クラスターに使用される SKU。 |
| レベル |
Standard |
SKU の階層。 |
| キャパシティ |
番号 |
クラスターのインスタンスの数。 |
| resource_group_name |
testrg |
クラスターが作成されるリソース グループの名前。 |
注
クラスターの作成は、実行時間の長い操作となります。 メソッド begin_create_or_update からは LROPoller のインスタンスが返されます。詳細については、LROPoller クラスを参照してください。
クラスターが正常に作成されたかどうかを確認するには、次のコマンドを実行します。
cluster_operations.get(resource_group_name = resource_group_name, cluster_name= cluster_name, custom_headers=None, raw=False)
結果に provisioningState が Succeeded として含まれていることを確認して、クラスターの正常な作成を確認します。
次のコードは、クラスターの作成方法を示しています。
前提条件にあるサービス プリンシパル情報を含む必要な環境変数を設定します。 クラスターを作成するサブスクリプション ID、リソース グループ、リージョンを入力します。
export AZURE_CLIENT_ID="<enter service principal client ID>"
export AZURE_CLIENT_SECRET="<enter service principal client secret>"
export AZURE_TENANT_ID="<enter tenant ID>"
export SUBSCRIPTION="<enter subscription ID>"
export RESOURCE_GROUP="<enter resource group name>"
export LOCATION="<enter azure location e.g. Southeast Asia>"
export CLUSTER_NAME_PREFIX="<enter prefix (cluster name will be [prefix]-ADXTestCluster)>"
export DATABASE_NAME_PREFIX="<enter prefix (database name will be [prefix]-ADXTestDB)>"
次のコードを実行して、クラスターを作成します。
import (
"context"
"log"
"os"
"strconv"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/kusto/armkusto"
"github.com/olekukonko/tablewriter"
)
const (
subscriptionEnvVar = "AZURE_SUBSCRIPTION_ID"
resourceGroupEnvVar = "AZURE_RESOURCE_GROUP"
locationEnvVar = "AZURE_LOCATION"
clusterNamePrefixEnvVar = "CLUSTER_NAME_PREFIX"
dbNamePrefixEnvVar = "DATABASE_NAME_PREFIX"
clusterName = "ADXTestCluster"
databaseName = "ADXTestDB"
)
func init() {
subscription = os.Getenv(subscriptionEnvVar)
if subscription == "" {
log.Fatalf("missing environment variable %s", subscriptionEnvVar)
}
rgName = os.Getenv(resourceGroupEnvVar)
if rgName == "" {
log.Fatalf("missing environment variable %s", resourceGroupEnvVar)
}
location = os.Getenv(locationEnvVar)
if location == "" {
log.Fatalf("missing environment variable %s", locationEnvVar)
}
clusterNamePrefix = os.Getenv(clusterNamePrefixEnvVar)
if clusterNamePrefix == "" {
log.Fatalf("missing environment variable %s", clusterNamePrefixEnvVar)
}
dbNamePrefix = os.Getenv(dbNamePrefixEnvVar)
if dbNamePrefix == "" {
log.Fatalf("missing environment variable %s", dbNamePrefixEnvVar)
}
}
func getClustersClient(subscription string) *armkusto.ClustersClient {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatal(err)
}
client, err := armkusto.NewClustersClient(subscription, cred, nil)
if err != nil {
log.Fatal(err)
}
return client
}
// 1 instance, Basic tier with compute type Dev(No SLA)_Standard_D11_v2
func createCluster(sub, name, location, rgName string) {
ctx := context.Background()
numInstances := int32(1)
client := getClustersClient(sub)
result, err := client.BeginCreateOrUpdate(
ctx,
rgName,
name,
armkusto.Cluster{
Location: &location,
SKU: &armkusto.AzureSKU{
Name: to.Ptr(armkusto.AzureSKUNameDevNoSLAStandardD11V2),
Capacity: &numInstances,
Tier: to.Ptr(armkusto.AzureSKUTierBasic),
},
},
nil,
)
if err != nil {
log.Fatal("failed to start cluster creation ", err)
}
log.Printf("waiting for cluster creation to complete - %s\n", name)
r, err := result.PollUntilDone(ctx, nil)
if err != nil {
log.Fatal(err)
}
log.Printf("created cluster %s\n", *r.Name)
}
createCluster(subscription, clusterNamePrefix+clusterName, location, rgName)
クラスターを一覧表示して、正常に作成されたことを確認します。
func listClusters(sub, rgName string) {
log.Printf("listing clusters in resource group %s\n", rgName)
ctx := context.Background()
result := getClustersClient(sub).NewListByResourceGroupPager(rgName, nil)
data := [][]string{}
for result.More() {
temp, err := result.NextPage(ctx)
if err != nil {
log.Fatal(err)
}
for _, c := range temp.Value {
data = append(data, []string{*c.Name, string(*c.Properties.State), *c.Location, strconv.Itoa(int(*c.SKU.Capacity)), *c.Properties.URI})
}
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "State", "Location", "Instances", "URI"})
for _, v := range data {
table.Append(v)
}
table.Render()
}
listClusters(subscription, rgName)
Important
Azure CLIの Kusto 拡張機能は古く、管理されていません。 クラスターとデータベースの作成には、PowerShell または ARM/Bicep テンプレートを使用することをお勧めします。 Azure CLIを使用する場合は、Kusto 拡張機能をインストールして、Azure Data Explorer用の最新の CLI コマンドがあることを確認してください。
次のコマンドを使用して、クラスターを作成します。
az kusto cluster create --cluster-name azureclitest --sku name="Standard_E8ads_v5" tier="Standard" --resource-group testrg --location westus
|
設定 |
推奨値 |
フィールドの説明 |
| 名前 |
azureclitest |
クラスターの任意の名前。 |
| sku |
Standard_E8ads_v5 |
クラスターに使用される SKU。 パラメーター: name - SKU 名。
tier - SKU レベル。 |
| リソース グループ |
testrg |
クラスターが作成されるリソース グループの名前。 |
| 位置 |
westus |
クラスターが作成される場所。 |
使用できるその他の省略可能なパラメーターが存在します (クラスターの容量など)。
クラスターが正常に作成されたかどうかを確認するには、次のコマンドを実行します。
az kusto cluster show --cluster-name azureclitest --resource-group testrg
結果に provisioningState が Succeeded として含まれていることを確認して、クラスターの正常な作成を確認します。
Azure Data Explorer データベースを作成する
このセクションでは、前のセクションで作成したクラスター内にデータベースを作成します。
クラスターとデータベースは、前のセクションの ARM テンプレートと共に作成されます。
クラスターとデータベースは、前のセクションのBicep テンプレートと共に作成されます。
次のコマンドを使用して、データベースを作成します。
New-AzKustoDatabase -ResourceGroupName testrg -ClusterName mykustocluster -Name mykustodatabase -SoftDeletePeriod 3650:00:00:00 -HotCachePeriod 3650:00:00:00
|
設定 |
推奨値 |
フィールドの説明 |
| ClusterName |
mykustocluster |
データベースの作成先となるクラスターの名前。 |
| 名前 |
mykustodatabase |
データベースの名前。 |
| ResourceGroupName |
testrg |
クラスターが作成されるリソース グループの名前。 |
| SoftDeletePeriod |
3650:00:00:00 |
データをクエリに使用できるようにしておく時間。 |
| HotCachePeriod |
3650:00:00:00 |
データをキャッシュに保持する時間。 |
次のコマンドを実行して、作成したデータベースを確認します。
Get-AzKustoDatabase -ClusterName mykustocluster -ResourceGroupName testrg -Name mykustodatabase
次のコードを使用してデータベースを作成します。
var cluster = (await clusters.GetAsync(clusterName)).Value;
var databases = cluster.GetKustoDatabases();
var databaseName = "mykustodatabase";
var softDeletePeriod = TimeSpan.FromDays(3650);
var hotCachePeriod = TimeSpan.FromDays(3650);
var databaseData = new KustoReadWriteDatabase
{
Location = clusterData.Location, SoftDeletePeriod = softDeletePeriod, HotCachePeriod = hotCachePeriod
};
await databases.CreateOrUpdateAsync(WaitUntil.Completed, databaseName, databaseData);
注
C# バージョン 2.0.0 以前を使用している場合は、ReadWriteDatabase ではなく Database を使用します。
|
設定 |
推奨値 |
フィールドの説明 |
| clusterName |
mykustocluster |
データベースの作成先となるクラスターの名前。 |
| databaseName |
mykustodatabase |
データベースの名前。 |
| resourceGroupName |
testrg |
クラスターが作成されるリソース グループの名前。 |
| softDeletePeriod |
3650:00:00:00 |
データをクエリに使用できるようにしておく時間。 |
| hotCachePeriod |
3650:00:00:00 |
データをキャッシュに保持する時間。 |
次のコマンドを実行して、作成したデータベースを確認します。
databaseData = (await databases.GetAsync(databaseName)).Value.Data as KustoReadWriteDatabase;
次のコマンドを使用して、データベースを作成します。
from azure.mgmt.kusto import KustoManagementClient
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.kusto.models import ReadWriteDatabase
from datetime import timedelta
#Directory (tenant) ID
tenant_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
#Application ID
client_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
#Client Secret
client_secret = "xxxxxxxxxxxxxx"
subscription_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
credentials = ServicePrincipalCredentials(
client_id=client_id,
secret=client_secret,
tenant=tenant_id
)
location = 'Central US'
resource_group_name = 'testrg'
cluster_name = 'mykustocluster'
soft_delete_period = timedelta(days=3650)
hot_cache_period = timedelta(days=3650)
database_name = "mykustodatabase"
kusto_management_client = KustoManagementClient(credentials, subscription_id)
database_operations = kusto_management_client.databases
database = ReadWriteDatabase(location=location,
soft_delete_period=soft_delete_period,
hot_cache_period=hot_cache_period)
poller = database_operations.begin_create_or_update(resource_group_name = resource_group_name, cluster_name = cluster_name, database_name = database_name, parameters = database)
poller.wait()
注
Python バージョン 0.4.0 以前を使用している場合は、ReadWriteDatabase ではなく Database を使用します。
|
設定 |
推奨値 |
フィールドの説明 |
| cluster_name |
mykustocluster |
データベースの作成先となるクラスターの名前。 |
| database_name |
mykustodatabase |
データベースの名前。 |
| resource_group_name |
testrg |
クラスターが作成されるリソース グループの名前。 |
| 論理削除期間 |
3650 日、0:00:00 |
データをクエリに使用できるようにしておく時間。 |
| hot_cache_period |
3650 日、0:00:00 |
データをキャッシュに保持する時間。 |
次のコマンドを実行して、作成したデータベースを確認します。
database_operations.get(resource_group_name = resource_group_name, cluster_name = cluster_name, database_name = database_name)
次のコードは、データベースの作成方法を示しています。 パッケージのインポートと環境変数の開始は、前のセクションの場合と同じです。
次のコードを実行して、データベースを作成します。
func createDatabase(sub, rgName, clusterName, location, dbName string) {
ctx := context.Background()
client := getDBClient(sub)
future, err := client.BeginCreateOrUpdate(ctx, rgName, clusterName, dbName, &armkusto.ReadWriteDatabase{Kind: to.Ptr(armkusto.KindReadWrite), Location: &location}, nil)
if err != nil {
log.Fatal("failed to start database creation ", err)
}
log.Printf("waiting for database creation to complete - %s\n", dbName)
resp, err := future.PollUntilDone(ctx, nil)
if err != nil {
log.Fatal(err)
}
kdb := resp.GetDatabase()
log.Printf("created DB %s with ID %s and type %s\n", *kdb.Name, *kdb.ID, *kdb.Type)
}
createDatabase(subscription, rgName, clusterNamePrefix+clusterName, location, dbNamePrefix+databaseName)
データベースを一覧表示して、正常に作成されたことを確認します。
func listDatabases(sub, rgName, clusterName string) {
log.Printf("listing databases in cluster %s\n", clusterName)
ctx := context.Background()
result := getDBClient(sub).NewListByClusterPager(rgName, clusterName, nil)
data := [][]string{}
for result.More() {
temp, err := result.NextPage(ctx)
if err != nil {
log.Fatal(err)
}
for _, db := range temp.Value {
if *db.GetDatabase().Kind == armkusto.KindReadWrite {
data = append(data, []string{*db.GetDatabase().Name, string(*db.GetDatabase().Kind), *db.GetDatabase().Location, *db.GetDatabase().Type})
}
}
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "State", "Location", "Type"})
for _, v := range data {
table.Append(v)
}
table.Render()
}
listDatabases(subscription, rgName, clusterNamePrefix+clusterName)
Important
Azure CLIの Kusto 拡張機能は古く、管理されていません。 クラスターとデータベースの作成には、PowerShell または ARM/Bicep テンプレートを使用することをお勧めします。 Azure CLIを使用する場合は、Kusto 拡張機能をインストールして、Azure Data Explorer用の最新の CLI コマンドがあることを確認してください。
次のコマンドを使用して、データベースを作成します。
az kusto database create --cluster-name azureclitest --database-name clidatabase --resource-group testrg --read-write-database soft-delete-period=P365D hot-cache-period=P31D location=westus
|
設定 |
推奨値 |
フィールドの説明 |
| クラスター名 |
azureclitest |
データベースの作成先となるクラスターの名前。 |
| データベース名 |
clidatabase |
データベースの名前。 |
| リソース グループ |
testrg |
クラスターが作成されるリソース グループの名前。 |
| 読み取り/書き込みデータベース |
P365DP31Dwestus |
データベースの種類。 パラメーター: soft-delete-period - データをクエリに使用できるようにしておく時間を示します。 詳細については、アイテム保持ポリシーに関するページを参照してください。
hot-cache-period - データをキャッシュに保持する時間を示します。 詳細については、キャッシュ ポリシーに関するページを参照してください。
location - データベースが作成される場所。 |
次のコマンドを実行して、作成したデータベースを確認します。
az kusto database show --database-name clidatabase --resource-group testrg --cluster-name azureclitest
次のステップ