Edit

Tutorial: Add Azure AI Search to a C# web app on Azure Container Apps

Note

Azure AI Search is available through the Azure portal, REST APIs, and Azure SDKs. It also underpins Foundry IQ, the managed knowledge layer that transforms enterprise content into reusable, permission-aware knowledge bases for agents in the Microsoft Foundry portal.

This tutorial builds a website that searches through a catalog of books and deploys the website to Azure Container Apps. The deployment uses the Azure Developer CLI (azd) and managed identity as the default authentication method for Azure AI Search.

In this tutorial, you:

  • Deploy Azure AI Search and auto-seed an index with the Azure Developer CLI.
  • Integrate search queries, suggestions, facets, pagination, and document lookup in the C# app.
  • Deploy the app to Azure Container Apps with managed identity as the default authentication method.

What does the sample do?

This sample website provides access to a catalog of 10,000 books. You can search the catalog by entering text in the search bar. While you enter text, the website uses the search index's suggestion feature to autocomplete the text.

When the query finishes, the website displays the list of books with a portion of their details. You can select a book to see its complete details, which are stored in the search index.

Screenshot of the sample app in a browser window.

The search experience includes:

  • Search - Provides search functionality for the application.
  • Suggest - Provides suggestions as the user types in the search bar.
  • Facets and filters - Provides a faceted navigation structure that filters by author or language.
  • Paginated results - Provides paging controls for scrolling through results.
  • Document lookup - Looks up a document by ID to retrieve all of its contents for the details page.

How is the sample organized?

The sample code includes the following components:

App Purpose GitHub repository location
client React app (presentation layer) to display books with search. It calls the API. /azure-search-static-web-app/client
api C# Azure Functions API (business layer), hosted in a container on Azure Container Apps, that calls the Azure AI Search API with the .NET SDK. /azure-search-static-web-app/api
bulk-insert .NET project that creates the index and loads documents. The azd deployment runs this automatically through the postprovision hook. /azure-search-static-web-app/bulk-insert
infra Bicep infrastructure used by azd to deploy Azure AI Search, Azure Container Apps, and supporting resources. Azure-Samples/azure-search-static-web-app

Set up your development environment

Install the following software for your local development environment. The azd up command provisions all Azure resources, including Azure AI Search, so you don't need to create them beforehand.

This tutorial doesn't run the Azure Functions API locally. If you want to run it locally, install Azure Functions Core Tools.

Clone the search sample with Git

You can deploy the sample from a local clone. The azd up command reads the application and infrastructure files from your local repository, builds the containers, provisions Azure resources, and deploys the client and API to Azure Container Apps.

  1. In a Bash terminal, clone the sample application to your local computer.

    git clone https://github.com/Azure-Samples/azure-search-static-web-app.git
    
  2. In the same Bash terminal, go to the repository directory for this search example.

    cd azure-search-static-web-app
    
  3. Use the Visual Studio Code command, code ., to open the repository. Unless otherwise specified, you complete the remaining tasks in Visual Studio Code.

    code .
    

Next step