DEV Community

Cover image for Azure Search with SQL Server
Emily Freeman for Microsoft Azure

Posted on

Azure Search with SQL Server

Thank you to Michael Crump for creating this content!

Don't have Azure? Grab a free subscription.


Implementing Azure Search with SQL Server and ASP.NET MVC

Today's tutorial covers Azure Search and SQL Server in a ASP.NET MVC web app.

What's Azure Search?

Azure Search is a SaaS — in this case, search-as-a-service — cloud solution that allows you to access REST APIs (along with an SDK) to search over your content using web, desktop or mobile apps.

There are a variety of services to which you can attach Azure Search, including SQL Server.

Creating the Indexer

This requires creating a SQL Server Database in which we'll store the indexer.

  1. Go into the Azure Portal.
  2. Search for "SQL Server" and click the Add button.
  3. Give it a database name and resource group.
  4. Fill out the new server information.
  5. Click on the Additional settings tab.
  6. In "Use existing data" select "Sample". This will use AdventureWorksLT as the sample database.

Additional Settings, Select Sample

Remember! Double check you selected theAdventureWorksLT database if you want to follow along with this tutorial.

AdventureWorks is an example database we've built just for you!

Taking A Peek at the Data

Now that we have a sample database and it has deployed, let’s use Query Editor inside the SQL Server blade to take a look at the table structure.

You can also use SQL Server Management Studio if you prefer it better.

If you click on Query Editor and login as instructed, then you’ll see the following:

query editor

As you can see, I expanded the Table dropdown and I can drill down again to the column names.

It looks like Customer would be a great table to implement search and we could pass in the FirstName or LastName field.

implement search

Trying writing a simple query to select the FirstName and LastName from SalesLT.Customer. Click Run to take a look at the data.

run

Now that we have our database in place and some solid data to work with, we’ll implement Azure Search.

Implementing Azure Search

Let's add Azure Search to our existing SQL Server instance.

  1. Open the Azure Portal.
  2. Navigate to your SQL Server instance and begin by looking at the Settings pane.

settings pane

Select a Add Azure Search and fill out the fields specified below and make sure to select the price as free.

add search

Under Data Source, we can easily connect to our Azure SQL Database.

  1. Give it a name.
  2. Provide the userid and password specified when setting up the SQL database.
  3. Press Test Connection.
  4. If everything goes well, then you’ll be able to select the Customer table.

customer table

Next, set an index.

  1. Give it a name.
  2. Select CustomerID as your key.
  3. Clean up the fields by deleting any you don't want.
  4. Make sure the fields can be retrieved, sorted, filtered and are searchable by adding a check like the photo below.

add a check

We need to create an indexer. I’m going to select the daily schedule and set my watermark column to the ModifiedDate as I assume data is unique in that column.

create an indexer

Once you kick that off, you’ll see the following notification. It states you can check the monitor progress and once complete you can start searching.

notifications

If you go ahead and click on the link on the notification window, then you’ll see the following screen.

execution history

Go ahead and press the Run button and it will start immediately. Eventually — expected time varies — you’ll see it has completed.

run it

Excellent! Our SQL database and Azure Search indexer are in place.

Want to know more about Azure Search? Check out our quickstarts and tutorials!


We'll be posting articles every day in April, so stay tuned! Or jump ahead and check out more tips and tricks now.

Top comments (0)