Skip to content

Commit 07c8982

Browse files
authored
Merge pull request #106024 from HeidiSteen/heidist-master
Standardized steps for Azure SQL DB tutorial
2 parents 098de27 + 376785a commit 07c8982

File tree

1 file changed

+68
-66
lines changed

1 file changed

+68
-66
lines changed

articles/search/search-indexer-tutorial.md

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ ms.date: 02/28/2020
1212
#Customer intent: As a developer, I want an introduction the indexing Azure SQL data for Azure Cognitive Search.
1313
---
1414

15-
# Tutorial: Index data from Azure SQL databases in C#
15+
# Tutorial: Use C# to index data from SQL databases in Azure Cognitive Search
1616

17-
Configure an [indexer](search-indexer-overview.md) programmatically to extract searchable data from Azure SQL database and sends it to a search index in Azure Cognitive Search.
17+
Configure an [indexer](search-indexer-overview.md) to extract searchable data from Azure SQL database, sending it to a search index in Azure Cognitive Search.
1818

1919
This tutorial uses C# and the [.NET SDK](https://aka.ms/search-sdk) to perform the following tasks:
2020

2121
> [!div class="checklist"]
2222
> * Create a data source that connects to Azure SQL Database
23-
> * Configure an indexer
23+
> * Create an indexer
2424
> * Run an indexer to load data into an index
2525
> * Query an index as a verification step
2626
@@ -39,35 +39,13 @@ If you don't have an Azure subscription, create a [free account](https://azure.m
3939

4040
Source code for this tutorial is in the [DotNetHowToIndexer](https://github.com/Azure-Samples/search-dotnet-getting-started/tree/master/DotNetHowToIndexers) folder in the [Azure-Samples/search-dotnet-getting-started](https://github.com/Azure-Samples/search-dotnet-getting-started) GitHub repository.
4141

42-
## Get a key and URL
42+
## 1 - Create services
4343

44-
API calls require the service URL and an access key. A search service is created with both, so if you added Azure Cognitive Search to your subscription, follow these steps to get the necessary information:
45-
46-
1. [Sign in to the Azure portal](https://portal.azure.com/), and in your search service **Overview** page, get the URL. An example endpoint might look like `https://mydemo.search.windows.net`.
47-
48-
1. In **Settings** > **Keys**, get an admin key for full rights on the service. There are two interchangeable admin keys, provided for business continuity in case you need to roll one over. You can use either the primary or secondary key on requests for adding, modifying, and deleting objects.
49-
50-
![Get an HTTP endpoint and access key](media/search-get-started-postman/get-url-key.png "Get an HTTP endpoint and access key")
51-
52-
## Set up connections
44+
This tutorial uses Azure Cognitive Search for indexing and queries, and Azure SQL Database as an external data source. If possible, create both services in the same region and resource group for proximity and manageability. In practice, Azure SQL Database can be in any region.
5345

54-
1. Start Visual Studio and open **DotNetHowToIndexers.sln**.
46+
### Start with Azure SQL Database
5547

56-
1. In Solution Explorer, open **appsettings.json** and replace placeholder values with connection information to your search service. If the full URL is "https://my-demo-service.search.windows.net", the service name to provide is "my-demo-service".
57-
58-
```json
59-
{
60-
"SearchServiceName": "Put your search service name here",
61-
"SearchServiceAdminApiKey": "Put your primary or secondary API key here",
62-
"AzureSqlConnectionString": "Put your Azure SQL database connection string here",
63-
}
64-
```
65-
66-
The last entry requires an existing database. You'll create it in the next step.
67-
68-
## Prepare sample data
69-
70-
In this step, create an external data source on Azure SQL Database that an indexer can crawl. You can use the Azure portal and the *hotels.sql* file from the sample to create the dataset in Azure SQL Database. Azure Cognitive Search consumes flattened rowsets, such as one generated from a view or query. The SQL file in the sample solution creates and populates a single table.
48+
In this step, create an external data source on Azure SQL Database that an indexer can crawl. You can use the Azure portal and the *hotels.sql* file from the sample download to create the dataset in Azure SQL Database. Azure Cognitive Search consumes flattened rowsets, such as one generated from a view or query. The SQL file in the sample solution creates and populates a single table.
7149

7250
If you have an existing Azure SQL Database resource, you can add the hotels table to it, starting at step 4.
7351

@@ -103,59 +81,45 @@ If you have an existing Azure SQL Database resource, you can add the hotels tabl
10381
Server=tcp:{your_dbname}.database.windows.net,1433;Initial Catalog=hotels-db;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
10482
```
10583

106-
1. Paste the connection string into "AzureSqlConnectionString" as the third entry in **appsettings.json** file in Visual Studio.
107-
108-
```json
109-
{
110-
"SearchServiceName": "<placeholder-Azure-Search-service-name>",
111-
"SearchServiceAdminApiKey": "<placeholder-admin-key-for-Azure-Search>",
112-
"AzureSqlConnectionString": "Server=tcp:{your_dbname}.database.windows.net,1433;Initial Catalog=hotels-db;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
113-
}
114-
```
115-
116-
1. Enter your password into the connection string in the **appsettings.json** file. Database and user names will copy over in your connection string, but the password must be entered manually.
117-
118-
## Build the solution
119-
120-
Press F5 to build the solution. The program executes in debug mode. A console window reports the status of each operation.
121-
122-
![Console output](./media/search-indexer-tutorial/console-output.png "Console output")
123-
124-
Your code runs locally in Visual Studio, connecting to your search service on Azure, which in turn connects to Azure SQL Database and retrieves the dataset. With this many operations, there are several potential points of failure. If you get an error, check the following conditions first:
84+
You will need this connection string in the next exercise, setting up your environment.
12585

126-
+ Search service connection information that you provide is limited to the service name in this tutorial. If you entered the full URL, operations stop at index creation, with a failure to connect error.
86+
### Azure Cognitive Search
12787

128-
+ Database connection information in **appsettings.json**. It should be the ADO.NET connection string obtained from the portal, modified to include a username and password that are valid for your database. The user account must have permission to retrieve data. Your local client IP address must be allowed access.
88+
The next component is Azure Cognitive Search, which you can [create in the portal](search-create-service-portal.md). You can use the Free tier to complete this walkthrough.
12989

130-
+ Resource limits. Recall that the Free tier has limits of 3 indexes, indexers, and data sources. A service at the maximum limit cannot create new objects.
90+
### Get an admin api-key and URL for Azure Cognitive Search
13191

132-
## Check results
92+
API calls require the service URL and an access key. A search service is created with both, so if you added Azure Cognitive Search to your subscription, follow these steps to get the necessary information:
13393

134-
Use Azure portal to verify object creation, and then use **Search explorer** to query the index.
94+
1. [Sign in to the Azure portal](https://portal.azure.com/), and in your search service **Overview** page, get the URL. An example endpoint might look like `https://mydemo.search.windows.net`.
13595

136-
1. [Sign in to the Azure portal](https://portal.azure.com/), and in your search service **Overview** page, open each list in turn to verify the object is created. **Indexes**, **Indexers**, and **Data Sources** will have "hotels", "azure-sql-indexer", and "azure-sql", respectively.
96+
1. In **Settings** > **Keys**, get an admin key for full rights on the service. There are two interchangeable admin keys, provided for business continuity in case you need to roll one over. You can use either the primary or secondary key on requests for adding, modifying, and deleting objects.
13797

138-
![Indexer and data source tiles](./media/search-indexer-tutorial/tiles-portal.png)
98+
![Get an HTTP endpoint and access key](media/search-get-started-postman/get-url-key.png "Get an HTTP endpoint and access key")
13999

140-
1. Select the hotels index. On the hotels page, **Search explorer** is the first tab.
100+
## 2 - Set up your environment
141101

142-
1. Click **Search** to issue an empty query.
102+
1. Start Visual Studio and open **DotNetHowToIndexers.sln**.
143103

144-
The three entries in your index are returned as JSON documents. Search explorer returns documents in JSON so that you can view the entire structure.
104+
1. In Solution Explorer, open **appsettings.json** to provide connection information.
145105

146-
![Query an index](./media/search-indexer-tutorial/portal-search.png "Query an index")
147-
148-
1. Next, enter a search string: `search=river&$count=true`.
106+
1. For `searchServiceName`, if the full URL is "https://my-demo-service.search.windows.net", the service name to provide is "my-demo-service".
149107

150-
This query invokes full text search on the term `river`, and the result includes a count of the matching documents. Returning the count of matching documents is helpful in testing scenarios when you have a large index with thousands or millions of documents. In this case, only one document matches the query.
108+
1. For `AzureSqlConnectionString`, the string format is similar to this: `"Server=tcp:{your_dbname}.database.windows.net,1433;Initial Catalog=hotels-db;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"`
151109

152-
1. Lastly, enter a search string that limits the JSON output to fields of interest: `search=river&$count=true&$select=hotelId, baseRate, description`.
110+
```json
111+
{
112+
"SearchServiceName": "<placeholder-Azure-Search-service-name>",
113+
"SearchServiceAdminApiKey": "<placeholder-admin-key-for-Azure-Search>",
114+
"AzureSqlConnectionString": "<placeholder-ADO.NET-connection-string",
115+
}
116+
```
153117

154-
The query response is reduced to selected fields, resulting in more concise output.
118+
1. In the connection string, make sure the connection string contains a valid password. While the database and user names will copy over, the password must be entered manually.
155119

156-
## Explore the code
120+
## 3 - Create the pipeline
157121

158-
Now that you understand what the sample code creates, let's return to the solution to review the code. Relevant code is in two files:
122+
Indexers require a data source object and an index. Relevant code is in two files:
159123

160124
+ **hotel.cs**, containing a schema that defines the index
161125
+ **Program.cs**, containing functions for creating and managing structures in your service
@@ -229,6 +193,44 @@ An indexer object is platform-agnostic, where configuration, scheduling, and in
229193
}
230194
```
231195

196+
## 4 - Build the solution
197+
198+
Press F5 to build and run the solution. The program executes in debug mode. A console window reports the status of each operation.
199+
200+
![Console output](./media/search-indexer-tutorial/console-output.png "Console output")
201+
202+
Your code runs locally in Visual Studio, connecting to your search service on Azure, which in turn connects to Azure SQL Database and retrieves the dataset. With this many operations, there are several potential points of failure. If you get an error, check the following conditions first:
203+
204+
+ Search service connection information that you provide is limited to the service name in this tutorial. If you entered the full URL, operations stop at index creation, with a failure to connect error.
205+
206+
+ Database connection information in **appsettings.json**. It should be the ADO.NET connection string obtained from the portal, modified to include a username and password that are valid for your database. The user account must have permission to retrieve data. Your local client IP address must be allowed access.
207+
208+
+ Resource limits. Recall that the Free tier has limits of 3 indexes, indexers, and data sources. A service at the maximum limit cannot create new objects.
209+
210+
## 5 - Search
211+
212+
Use Azure portal to verify object creation, and then use **Search explorer** to query the index.
213+
214+
1. [Sign in to the Azure portal](https://portal.azure.com/), and in your search service **Overview** page, open each list in turn to verify the object is created. **Indexes**, **Indexers**, and **Data Sources** will have "hotels", "azure-sql-indexer", and "azure-sql", respectively.
215+
216+
![Indexer and data source tiles](./media/search-indexer-tutorial/tiles-portal.png)
217+
218+
1. Select the hotels index. On the hotels page, **Search explorer** is the first tab.
219+
220+
1. Click **Search** to issue an empty query.
221+
222+
The three entries in your index are returned as JSON documents. Search explorer returns documents in JSON so that you can view the entire structure.
223+
224+
![Query an index](./media/search-indexer-tutorial/portal-search.png "Query an index")
225+
226+
1. Next, enter a search string: `search=river&$count=true`.
227+
228+
This query invokes full text search on the term `river`, and the result includes a count of the matching documents. Returning the count of matching documents is helpful in testing scenarios when you have a large index with thousands or millions of documents. In this case, only one document matches the query.
229+
230+
1. Lastly, enter a search string that limits the JSON output to fields of interest: `search=river&$count=true&$select=hotelId, baseRate, description`.
231+
232+
The query response is reduced to selected fields, resulting in more concise output.
233+
232234
## Reset and rerun
233235

234236
In the early experimental stages of development, the most practical approach for design iteration is to delete the objects from Azure Cognitive Search and allow your code to rebuild them. Resource names are unique. Deleting an object lets you recreate it using the same name.

0 commit comments

Comments
 (0)