トレーニング
認定資格
Microsoft Certified: Azure Cosmos DB Developer Specialty - Certifications
Microsoft Azure Cosmos DB を使用して SQL API と SDK で効率的なクエリの作成、インデックス作成ポリシーの作成、リソースの管理とプロビジョニングを行います。
このブラウザーはサポートされなくなりました。
Microsoft Edge にアップグレードすると、最新の機能、セキュリティ更新プログラム、およびテクニカル サポートを利用できます。
次の手順に従って、引き続き検索が有効な Web サイトを構築します。
このプログラムでは、Azure SDK for .NET で Azure.Search.Documents を使用します。
開始する前に、新しいインデックスの検索サービスに余裕があることを確認してください。 Free レベルのインデックス制限は 3 です。 Basic レベルの制限は 15 です。
Visual Studio Code で、サブディレクトリ azure-search-static-web-app/bulk-insert
内の Program.cs
ファイルを開き、次の変数を実際の値に置き換えて、Azure Search SDK による認証を行います。
using Azure;
using Azure.Search.Documents;
using Azure.Search.Documents.Indexes;
using Azure.Search.Documents.Indexes.Models;
using AzureSearch.BulkInsert;
using ServiceStack;
const string BOOKS_URL = "https://raw.githubusercontent.com/Azure-Samples/azure-search-sample-data/main/good-books/books.csv";
const string SEARCH_ENDPOINT = "https://YOUR-SEARCH-RESOURCE-NAME.search.windows.net";
const string SEARCH_KEY = "YOUR-SEARCH-ADMIN-KEY";
const string SEARCH_INDEX_NAME = "good-books";
Uri searchEndpointUri = new(SEARCH_ENDPOINT);
SearchClient client = new(
searchEndpointUri,
SEARCH_INDEX_NAME,
new AzureKeyCredential(SEARCH_KEY));
SearchIndexClient clientIndex = new(
searchEndpointUri,
new AzureKeyCredential(SEARCH_KEY));
await CreateIndexAsync(clientIndex);
await BulkInsertAsync(client);
static async Task CreateIndexAsync(SearchIndexClient clientIndex)
{
Console.WriteLine("Creating (or updating) search index");
SearchIndex index = new BookSearchIndex(SEARCH_INDEX_NAME);
var result = await clientIndex.CreateOrUpdateIndexAsync(index);
Console.WriteLine(result);
}
static async Task BulkInsertAsync(SearchClient client)
{
Console.WriteLine("Download data file");
using HttpClient httpClient = new();
var csv = await httpClient.GetStringAsync(BOOKS_URL);
Console.WriteLine("Reading and parsing raw CSV data");
var books =
csv.ReplaceFirst("book_id", "id").FromCsv<List<BookModel>>();
Console.WriteLine("Uploading bulk book data");
_ = await client.UploadDocumentsAsync(books);
Console.WriteLine("Finished bulk inserting book data");
}
プロジェクト ディレクトリのサブディレクトリ (azure-search-static-web-app/bulk-insert
) の統合ターミナルを Visual Studio Code で開きます。
次のコマンドを実行して、依存関係をインストールします。
dotnet restore
引き続き同じサブディレクトリ (azure-search-static-web-app/bulk-insert
) で、次のプログラムを実行します。
dotnet run
コードを実行すると、コンソールに進行状況が表示されます。 次の出力が表示されます。
Creating (or updating) search index
Status: 201, Value: Azure.Search.Documents.Indexes.Models.SearchIndex
Download data file
Reading and parsing raw CSV data
Uploading bulk book data
Finished bulk inserting book data
アップロードが完了すると、検索インデックスを使用できるようになります。 Azure portal で新しいインデックスを確認します。
Azure portal で、ご利用の検索サービスを探します。
左側の [検索管理] > [インデックス] を選択し、適切なブックのインデックスを選択します。
既定では、インデックスは [Search エクスプローラー] タブで開きます。[検索] を選択して、インデックスからドキュメントを返します。
次の git コマンドを Visual Studio Code 統合ターミナルの bulk-insert
ディレクトリで使用して、変更を Program.cs
ファイルにロールバックします。 これらはチュートリアルを続行するために必要ありません。また、API キーや検索サービス名をリポジトリに保存したりプッシュしたりしないでください。
git checkout .
トレーニング
認定資格
Microsoft Certified: Azure Cosmos DB Developer Specialty - Certifications
Microsoft Azure Cosmos DB を使用して SQL API と SDK で効率的なクエリの作成、インデックス作成ポリシーの作成、リソースの管理とプロビジョニングを行います。