AZ-204 Microsoft Azure Developer Associate – Connect to and consume Azure and third-party services part 2
- AZ-203 – Lab – Index field attributes
Hi and welcome back. So in the last lab we had seen how to create a search account, how to create an index, and how to upload documents onto the index using the rest API. Now let’s go ahead and experiment with the different attributes that we have assigned to the fields. So first let’s look at how we can build a query string using the filterable attribute. So we can go on to the Search Explorer. And here we can add the query string. So let’s say that you want to filter the documents based on the name. So since we have marked the name field has filterable, we can add a filter to the query string as so. So we add the filter what is the field for the filter? And here we’re saying that please return the documents wherein the name is equal to user B. So let’s go ahead and click on Search.
And now you can see you’re only getting the documents where the name is equal to user B. So this is how you can use the filterable attribute to filter on the documents in your particular index. Now let’s look at the next attribute which is the facetrable attribute. So now we have marked the course field has facetible. So if you go on to the Search Explorer here I’m adding the query string. So facet is equal to cost. Let’s click on Search and let’s see what happens. So now you can see that you’re getting a grouping based on the course. So you have two documents which have the value of this course and then you have one matching document which has the value for this course. So this is how you can use the facet in the query string.
Now let’s look at the progress which is marked as Sortable. If you go on to the Search Explorer here, I’m in the query string adding the order by clause so that we can sort the documents via the progress field. Let’s click on search. And now you can see that the documents are being sorted in order of the progress field. Now lastly, we have the command field. Now in the command field we’ve marked it as Searchable. So this is like performing a full text search. So if you go on to our Search Explorer so these are the different comments that we have. So the course needs improvement, the course is good and the course really has a lot of good aspects. So if I just perform a free text search of good, let me go ahead and click on Search.
So now you can see that you are getting only those documents wherein good is mentioned in the comment field. Since we have marked the command field as Searchable, that’s why these two documents are coming up. You can also see the score being assigned to both documents based on the search itself. If you try to perform a free text search of the username, this should not work. And that’s because we have not marked that field as searchable. So because we have actually marked the command field as a free text search, we can actually really perform a free text search. All documents based on that field. Right. So this marks the end of this slide in which you’ve looked at examples of how we can use the attributes for the different fields.
- AZ-203 – Lab – Azure Search Indexer
Hi and welcome back. Now in this lab, let’s look at the Azio search indexer. So remember, the indexer can be used to connect an index to an existing external data source. So what are we going to see in this lab? We are going to create our external data source has a new Azure SQL database along with the sample database. And then we create an index by importing the data. This will use an indexer that will connect to the Azeo SQL database. So let’s go ahead and see how we can accomplish this. So here we are, azure. Now, first thing is first let’s go ahead and add a new SQL database. So I’ll choose the resource group. I’ll give a database name. I’ll create a new server. I’ll mention the server name, the admin login details, and also the location.
I’ll also allow Azure Services to access the server. This so that our Azeosarch account can access the SQL database. At the moment, I won’t use an elastic pool. Let me configure the database. So I’ll just go for the basic DTU. Since this is just a demo, I’ll click on Apply. I’ll go on to Next for additional settings. Now here I’ll ensure that the Sample database, the Adventure Works Lt database is basically part of this database server. I’ll go onto Next, go on to review and Create. And let me go ahead and hit on Create. So let’s come back once the SQL database is in place. So now that we have the database in place, let’s go on to the resource. Let me go on to set the firewall so that I can just allow my local machine to connect to the SQL database. So I can add the client IP. Click on save.
Now that this is done, if I go on to the database, if I go on to the server name here I have SQL Server Management Studio. So this is a freely open tool that’s available to connect and work with Microsoft SQL databases. I can enter the server name, enter the username and password. Click on connect. Now, once I’m connected so I can see my database over here, I can also see the tables that are part of the Adventure Work sample database. So these are the tables which are in place. Now let’s say that you want to have a zero search connect to, let’s say the customer table. So you want to build an index based on the customer table. So you can perform a search based on the data in this table. So we can go back onto all resource. Let’s go on to our search account.
Now, instead of going ahead and adding an index, let’s go ahead and import data. So this is another way in which we can add data onto an index. So here in the data source, you can choose the different data sources which are available, the different data source connectors. So I’m going to choose Azure SQL database. Let me choose an existing connection. So let me go ahead and choose the database. Let me give a name for the connection. Let me enter the password. Let me test the connection so the connection is validated. Next, I’ll go ahead and select the table that this index will connect to. So I’ll choose the customer table. Go on to next. Now, for the moment, I’m going to skip cognitive search. We have a separate lab on how we can implement this. I’ll go on to customize the target index.
So over here, it’s automatic taken all the fields from our table. Now we can decide what are the fields we want to include in the index. So I’ll just choose the first name, last name, the company name, and the salesperson. If you want, you can go ahead and mark the attributes for the different fields. You can go ahead and create an indexer. You can give a name for the indexer. You can create a schedule. So this is the amount of times that the indexer will actually go to the data in the database, see the changes, and then update the index based on the data changes in the database table. For now, I’ll just leave everything as this and click on Submit. So now it’s going ahead and configuring the index. So currently you can see we have two indexes in place if you go on to the index.
So again, you can see that the document count and the storage size is currently zero. Let’s come back once we have some documents as part of this index. Now, after some time when you refresh, you can now see the document count. So if you go on to the index itself, if you click on Search so now automatically it’s created documents based on the data in the SQL database. And now we can perform search on the data that’s in that customer table in the SQL database. So that is the entire purpose of the indexer. The indexer can be used to basically index data in an external data source, such as an Azure SQL database, azure Blob Storage, or Azure Cosmos DB. So this marks the end of this lab.
- AZ-203 – Lab – Azure Search – SDK
Hi and welcome back. Now let’s look at the program that can be used to interact with Azure Search. In this program, we will see how to create an index and how to upload documents onto the index. So first we have our search service name, which is Demo Search 2020. And then we have the Admin API key. So how do we get the Admin API key? Well, if you go on to your search account, if you go on to keys, you can take either the primary admin key or the secondary admin key. So you can go ahead, you can click on Copy, you can go on to your program and you can add it over here. Let me also go on to Tools. Let me look at the Nugget package manager. Let’s see what are the packages we have installed as part of the solution. So what is important is Microsoft Azure search. Please go ahead and install this package as part of your solution.
Let’s go back on the program. Let’s understand more about the program itself. So first I’m going ahead and creating a new search service client. Now, in the search service client, I am passing in the search service name and also the search credentials, which consists of the Admin API key. So first we need a client which will be used to connect to our search account. That’s the first thing. After that, I have two methods. One is to create an index and the other is to upload documents to the index. And in both, I’m mentioning what is the index. So I’m uploading both onto an index called Customer. Now, if I go on to the index creation method, first I’m going ahead and mentioning a definition. So what is going to be the definition of my index? So basically, what are going to be the fields for my index? And apart from the fields of index, what are going to be my attributes? So I’m building it from a class known as Customer. So I have a customer class within my program itself.
So if I go on to the Customer class over here, I have all the properties of my class, the ID, which is a string. Now remember that as part of the index, one of the fields has to be mentioned, has the key. So I’m using a dataanotations key. So this ensures that this field, when it is mapped on to the index, it is mentioned as the key for the index. Now, for each of the other fields of my index, I can actually specify what is the attribute for that particular field.So let’s say I want the name field to be marked as Filterable. So I can put this data annotation or this annotation label for this particular property of the class, if you want a particular field to have multiple attributes, this is how you can mention it. So for the course, I’m marking this particular field as Filterable. Sortable and fastable. So this is from the class level, and you mentioned this class to basically build the index in your Azure search account.
Let’s go back onto our program. So this is how we actually build the particular index. And then next we go ahead and use the client indexes create use that definition to go ahead and create the index. Now let’s go ahead and see how to upload documents to the index. So over here, I’m going ahead and uploading three documents onto our index. So I am just creating three objects, adding it to an array. If I scroll down, I then use an index patch upload method to basically upload my array. And then I’m going ahead and getting a handle to my current index. And then finally, I’m using the dot documents of the client, the index client, to basically upload my batch of documents onto the index, right? So let’s go ahead, run this program and see how it works.
So let’s go ahead and run the program. So first we’re going to run the program to create the index or the customer index. Now, if you go onto our search account, if you go on to indexes, if you already have an index in place, you can go actually simply delete the index. So now we don’t have the index, so we can go on to our program. Let’s run our program. So the index is created if you go on to the Search account. If you click on Refresh, you can now see the index. Now we can go ahead and run the program to upload the documents to the index. So it’s gone ahead and uploaded the documents onto the index. If you go on to the Search account, if you click on Refresh, you can now see that you have three documents in place. If you go on to the index, click on Search. You now have the documents as part of the index, right? So this marks the end of this chapter. You.
- AZ-203 – Lab – Azure Search – Cognitive Search
Hi and welcome back. Now in this lab, we are going to see how we can use the cognitive search feature in Azure search. So, cognitive search can be used to extract text from images, blobs and other unstructured data sources. This makes the search more extensive in nature. So you have a number of EIA enrichments that are supported with the cognitive searches. So, for example, you can use natural language processing, such as language detection and key phrase extraction. And you can use image processing, which uses the optical character recognition. So what exactly are we going to do in our lab? We’re going to create an Azure storage account. We’re going to add some images to the Blob service and we’ll add an index which will be connected to that Azure Blob service. And then we’ll use the cognitive search feature to extract the text in the images.
So let’s see how we can accomplish this. So here we are here. Let’s go ahead and add a storage account. So I’ll choose storage account, choose the resource group, give the storage account name. I’ll choose the location. I’ll leave the replication as locally redundant storage. Since this is just a demo, I’ll leave the networking hazardous, I’ll leave the advanced hazardous, leave the tags, go on to review and create, and then let me go ahead and create the storage account. Now, onto that Blob service, in the storage account, I’m just going to upload three JPEG images. So these are the images. So these are just some images which I have as part of my exams in my courses. Now there is some text in these images. So remember, these are all images.
These are not actually text based documents. So I have three images, but all of them have some text inside them. So we’re going to be using the cognitive feature in Azure to actually extract the text from these images and actually make it searchable through an index. Once the storage account is in place, we can go on to the resource. Let’s go on to the Blob service. Let’s create a new container. We’ll give the container a name. I’ll go on to the container and let me go ahead and upload those three images onto this container. So I’m going ahead and uploading those images. So all the three images are now in our container. Now let’s go over back onto our Azure search account. Let me go ahead and again import data.
Let me choose now the data sources. Azure Blob storage. Let me give a name for this connection. I’ll choose the data to extract as content and metadata. I’ll leave the passing mode as default. I’ll choose an existing connection. That means I have to choose my storage account and choose the container in the storage account. This will automatically choose the connection string. If you want, you can also have a folder in place. Let me go on to next. Now, in cognitive search, if you go on to cognitive services. So there is only one free cognitive resource in place for you to work with as your search. If you want you can go ahead and create a new one because this has some limited enrichments.
Now if you go on to adding of enrichments over here, let’s click on enable OCR. So this will actually go ahead and read that data from those images if you want then you can extract key phrases, translate the text, generate tags for the images, generate captions from the images. So these are the skills which are in place. You can go onto next to customize the target index. So these are all the fields I’ll leave everything hazardous and let me go onto next to go ahead and actually create the indexer. I can give a name for the indexer, let me click on Submit and let’s come back once the index is in place. So once the index is in place again you can see the document count is zero.
So let’s come back after some time once the index has gone to a zero, blob done its work and then place some documents in our index. So after some time you can now see the document count is three. So since we have three images, we seem to have now three documents in our index. If you go on to the Search Explorer. So here we are in our Azure Blob index. Let’s go ahead and click on search and now you can see that you’re actually getting the text in the image itself. So that cognitive service has actually gone ahead, understood the text in that image and is now given it has a field in the document in the index. So this marks the end of this lab in which we have seen how we could combine the cognitive service along with a zero search.