C# samples for Azure Cognitive Search

Learn about the C# code samples that demonstrate the functionality and workflow of an Azure Cognitive Search solution. These samples use the Azure Cognitive 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/master/sdk/search/Azure.Search.Documents/tests
Source code github.com/Azure/azure-sdk-for-net/tree/master/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/master/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.

Doc samples

Code samples from the Cognitive 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 Microsoft code samples in GitHub, filtered by product, service, and language.

Code sample Related article Purpose
quickstart Quickstart: Create a search index 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 a rich client plus components for hosting the app and handling search requests.
DotNetHowTo How to use the .NET client library Steps through the basic workflow, but in more detail and with discussion of API usage.
DotNetHowToSynonyms Example: Add synonyms in C# Synonym lists are used for query expansion, providing matchable terms that are external to an index.
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.
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.
tutorial-ai-enrichment Tutorial: AI-generated searchable content from Azure blobs Shows how to configure an indexer and skillset.
Create your first app in C# Tutorial: Create your first search app While most samples are console applications, this MVC sample uses a web page to front the sample Hotels index, demonstrating basic search, pagination, autocomplete and suggested queries, facets, and filters.

Other samples

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

Samples Description
Check storage Invokes an Azure function that checks search service storage on a schedule.
Export an index C# console app that partitions and export a large index.
Query multiple services Issue a single query across multiple search services and combine the results into a single page.
Index Data Lake Gen2 using Azure AD Source code demonstrating indexer connections and indexing of Azure Data Lake Gen2 files and folders that are secured through Azure AD and role-based access controls.
azure-search-power-skills Source code for consumable custom skills that you can incorporate in your won solutions.
Knowledge Mining Solution Accelerator Includes templates, support files, and analytical reports to help you prototype an end-to-end knowledge mining solution.
Covid-19 Search App repository Source code repository for the Cognitive Search based Covid-19 Search App
JFK Learn more about the JFK solution.
Search + QnA Maker Accelerator A solution combining the power of Search and QnA Maker. See the live demo site.