Index multiple data sources in Azure Cognitive Search
Demonstrates Azure Cognitive Search indexing from Azure Cosmos DB and Azure Blob storage, populating an index by combining data from different data sources.
This .NET Core console application is featured in C# Tutorial: Combine data from multiple data sources in one search index. When you run the program, a console window emits output messages for each step. This sample runs on an Azure Cognitive Search service, importing content from Azure Cosmos DB and Azure Blob storage, using services and connection information that you provide.
Clone or download this sample repository.
Extract contents if the download is a zip file. Make sure the files are read-write.
Create and populate a Cosmos DB data source with hotels information:
- In the Azure portal, create an Azure Cosmos DB account for the Core (SQL) API.
- Create a new database named "hotel-rooms-db".
- In Data Explorer, open the "hotel-rooms-db", create a new container named "hotels".
- Open "hotels", select Items, select Upload Item, and then select the src/cosmosdb/HotelsDataSubset_CosmosDB.json file. It contains data for seven hotels, but no rooms data.
- In the left pane, go to Settings > Keys and get the primary connection string. You will need this value for the appsettings.json file in the project.
Create and populate a Blob container with rooms information:
- In the Azure portal, create an Azure Storage account for blob content.
- Create a new blob storage container named "hotel-rooms".
- Select this container, click Upload, and then upload all of the JSON files in the src/blobs folder, ranging from Rooms1.json through Rooms15.json. These files contain room details for each of the seven hotels.
- In the left pane, go to Settings > Access Keys and get the connection string for key1. It also goes into the project's appsettings.json file.
This sample is available in two versions:
v10 uses the previous Microsoft.Azure.Search client libraries
v11 uses the new Azure.Search.Documents client library, highly recommended for all new projects
Run the sample
Open the sample solution in Visual Studio.
Edit the appsettings.json and fill in the appropriate account names, keys, and connection strings:
- SearchServiceName and SearchServiceAdminKey can be found in Overview and Keys portal pages of your Azure Cognitive Search service.
- Blob storage and Cosmos DB connection information can be found in the key pages.
- For Blob storage, you also need the name of the storage account.
Press F5 to build and run the app. Status messages appear in the console window.
After a successful run, you should see a new index named "hotel-rooms-sample" in your search service, containing the combined hotel and room data for all seven hotels.
- In the Azure portal, open the search service Overview page.
- In Indexes, select the new "hotel-rooms-sample" index containing seven documents.
- By default, the index opens in the Search explorer tab. Click Search to execute an empty search, returning all documents. Scroll down or use CTRL-F to verify that each hotel now has a "Rooms" collection with descriptions, rates, and other room-specific information.
You can learn more about Azure Cognitive Search on the official documentation site.