Azure Search - Load Data





This is the third post of blog series on Azure search. In previous post I explain how we can Provision Azure service and how we can create Index. In this post I am going to show you how we can load the data in Azure search service.

Now you can import the data which is already present in Azure services like SQL, Blob storage etc or you can import data from other service using code. If you use existing service, it is going to be a pull operation where indexer will crawl over your data and create indexes. Here I will be explaining how we can push the data to Azure search using .NET SDK.

Before jumping on code, let's take a moment and understand what are actions. Actions are nothing but the operations performed on data on the service, these operation can be

  • Upload: Will upload a new record in index.
  • Delete: Will delete an existing record.
  • Merge: Will merge the records with the existing one.
  • Merge Or Upload: Merge if exist otherwise upload the document.
Now to load the data we need to do the following 
  • Get the search service client 
  • Get the index client 
  • Prepare the Index Batch since we are going to load bulk data.
  • And Finally load the data.
Let's see these steps in action.

Step 1: Get the search service client. In last post, we create a method to return service client so let's use it.
Step 2: Get the index client, to get the index client use the following code.
Step 3: Prepare the Index Batch

Step 4: Finally Load the data.
The overall method should look like
Please note we at once we can only insert 1000 records. If you have more than 1000 records you need to break the operation in part.

Now just call this method from any action, I am executing it from Contact Action, So after executing the action I should see 3 records in Portal. Please note it might take up to 1 min to reflect the updated count in the portal, so please have some patients.



So that's it we are done with loading the data, in next step we will see how can search the data. 

Thanks for reading, happy learning.

Comments

Popular posts from this blog

Implement Open API specification in .NET Core Web API using Swagger.

Azure Search