C# samples for Azure AI Search

Learn about the C# code samples that demonstrate the functionality and workflow of an Azure AI Search solution. These samples use the Azure AI Search client library for the Azure SDK for .NET, which you can explore through the following links.

Target Link
Package download www.nuget.org/packages/Azure.Search.Documents/
API reference azure.search.documents
API test cases github.com/Azure/azure-sdk-for-net/tree/main/sdk/search/Azure.Search.Documents/tests
Source code github.com/Azure/azure-sdk-for-net/tree/main/sdk/search/Azure.Search.Documents/src

SDK samples

Code samples from the Azure SDK development team demonstrate API usage. You can find these samples in Azure/azure-sdk-for-net/tree/main/sdk/search/Azure.Search.Documents/samples on GitHub.

Samples Description
"Hello world", synchronously Demonstrates how to create a client, authenticate, and handle errors using synchronous methods.
"Hello world", asynchronously Demonstrates how to create a client, authenticate, and handle errors using asynchronous methods.
Service-level operations Demonstrates how to create indexes, indexers, data sources, skillsets, and synonym maps. This sample also shows you how to get service statistics and how to query an index.
Index operations Demonstrates how to perform an action on existing index, in this case getting a count of documents stored in the index.
FieldBuilderIgnore Demonstrates a technique for working with unsupported data types.
Indexing documents (push model) "Push" model indexing, where you send a JSON payload to an index on a service.
Encryption key sample Demonstrates using a customer-managed encryption key to add an extra layer of protection over sensitive content.
Vector search sample Shows you how to index a vector field and perform vector search using the Azure SDK for .NET.

Doc samples

Code samples from the Azure AI Search team demonstrate features and workflows. All of the following samples are referenced in tutorials, quickstarts, and how-to articles that explain the code in detail. You can find these samples in Azure-Samples/azure-search-dotnet-samples and in Azure-Samples/search-dotnet-getting-started on GitHub.

Tip

Try the Samples browser to search for Azure code samples in GitHub, filtered by product, service, and language.

Code sample Related article Purpose
create-mvc-app Tutorial: Add search to an ASP.NET Core (MVC) app While most samples are console applications, this MVC sample uses a web page to front the sample Hotels index, demonstrating basic search, pagination, and other server-side behaviors.
quickstart Quickstart: Full text search using the Azure SDKs Covers the basic workflow for creating, loading, and querying a search index in C# using sample data.
search-website Tutorial: Add search to web apps Demonstrates an end-to-end search app that includes bulk upload using the push APIs and a rich client for hosting the app and handling search requests.
tutorial-ai-enrichment Tutorial: AI-generated searchable content from Azure blobs Shows how to configure an indexer and skillset.
multiple-data-sources Tutorial: Index from multiple data sources. Merges content from two data sources into one search index.
Optimize-data-indexing Tutorial: Optimize indexing with the push API. Demonstrates optimization techniques for pushing data into a search index.
DotNetHowTo How to use the .NET client library Steps through the basic workflow, but in more detail and with discussion of API usage.
DotNetToIndexers Tutorial: Index Azure SQL data Shows how to configure an Azure SQL indexer that has a schedule, field mappings, and parameters.
DotNetHowToEncryptionUsingCMK How to configure customer-managed keys for data encryption Shows how to create objects that are encrypted with a Customer Key.
DotNetVectorDemo readme Create, load, and query a vector index.
DotNetIntegratedVectorizationDemo readme Extends the vector workflow to include skills-based automation for data chunking and embedding.

Accelerators

An accelerator is an end-to-end solution that includes code and documentation that you can adapt for your own implementation of a specific scenario.

Samples Repository Description
Search + QnA Maker Accelerator search-qna-maker-accelerator A solution combining the power of Search and QnA Maker. See the live demo site.
Knowledge Mining Solution Accelerator azure-search-knowledge-mining Includes templates, support files, and analytical reports to help you prototype an end-to-end knowledge mining solution.

Demos

A demo repo provides proof-of-concept source code for examples or scenarios shown in demonstrations. Demo solutions aren't designed for adaptation by customers.

Samples Repository Description
Covid-19 search app covid19search Source code repository for the Azure AI Search based Covid-19 Search App
JFK demo AzureSearch_JFK_Files Learn more about the JFK solution.

Other samples

The following samples are also published by the Azure AI Search team, but aren't referenced in documentation. Associated readme files provide usage instructions.

Samples Repository Description
Query multiple services azure-search-dotnet-scale Issue a single query across multiple search services and combine the results into a single page.
Check storage azure-search-dotnet-utilities Invokes an Azure function that checks search service storage on a schedule.
Export an index azure-search-dotnet-utilities C# console app that partitions and export a large index.
Backup and restore an index azure-search-dotnet-utilities C# console app that copies an index from one service to another, and in the process, creates JSON files on your computer with the index schema and documents.
Index Data Lake Gen2 using Microsoft Entra ID azure-search-dotnet-utilities Source code demonstrating indexer connections and indexing of Azure Data Lake Gen2 files and folders that are secured through Microsoft Entra ID and role-based access controls.
Search aggregations azure-search-dotnet-utilities Proof-of-concept source code that demonstrates how to obtain aggregations from a search index and then filter by them.
Power Skills azure-search-power-skills Source code for consumable custom skills that you can incorporate in your won solutions.