A Novice Guide to Azure AI Search
Tags: generativeai, index, machinelearning, azure
Published: 2024-03-28 22:30:47

---
title: A Novice Guide to Azure AI Search
published: true
description: 
tags: generativeai, index, machinelearning, azure
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2024-03-28 22:13 +0000
---
#Introduction
Azure AI Search provides an information retrieval service on a large amount of searchable data. For example document search, data exploration etc. You can use this service to enable powerful search capabilities within applications and solutions. Like Personalization, Insight Discovery, E-commerce Search, Healthcare Information Retrieval etc.

In Azure AI Search two term you need to know
* Indexing
* Querying

####Indexing:
The purpose of this process is to loads the dataset into Azure AI Search that you created and make it searchable. The data format of an Index is in JSON. So, you need to format your data into JSON format or use and indexer to retrieve and serialize your data into JSON. Index is like a table which contains fields and their data. And each row in Index contains a new sets of records which is called document.


####Querying:
You use query to search data based on a search criteria. Like retrieving a searchable content and associated document with the search terms.

Azure AI Search provides you the capability of full text search, keyword search. Also, you can use both to get most relevant results. Let's create our first search index and test some query to gain knowledge how Azure AI Search works.

#Create a search index:
In order to create a search, we to follow these steps. We will be using free tier for creating a service and data source connection to sample data hosted by Microsoft on Azure Cosmos DB.

####Step 01
* Go to Azure AI Search and create a resource and name it for example: FirstAISearch
* Create a search service and name it for example: firstaisearchservice. Please not that service name should be all lowercase.

Once service created successfully you will see the following successful message.

![create resource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3jxqfkuqw9vcy7aamnro.png)

####Step 02
Now go to overview menu from left hand side and select "Usage" tab to get the status of the service like indexes, indexers, and data sources you already have. Since we are using "free tier" it is limited to three indexes, three data sources, and three indexers.

![resource create1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s6kauhrvh47qimw6jf34.png)

![resource create2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3vbp0cpzxqvdg9eubsaq.png)

####Step 03
* On the "Overview" page in the top menu there is option call "Import Data"

![overview3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s28p666ajwaw6scphvui.png)

* On Connect to your data, select the data source "Samples" from dropdown list.
* In the list of built-in samples, select hotels-sample.
* Select Next: Add cognitive skills (Optional) to continue.
* For now, select Skip to: Customize target index to continue.

![step31](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/thzbqv5aozgpxovh4fmk.png)

![step32](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ww0mr2ei1t2jmcmd7og.png)

![step33](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t243i95bd9rwu12qrf3w.png)

####Step 04
Search service refers to a schema for the built-in hotels-sample index. Follow these steps to configure the index:

* Keep as it is the Index name "hotels-sample-index" and Key field "HotelId".
* Keep values for all field attributes as it is.
* Select Next: Create an indexer to continue.

![step4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5er2bcos2an5jnf0gts1.png)

For creating the index it requires an Index name and a collection of Fields. One field must be marked as the document key to uniquely identify each document and the value is always a string.

Each field has a name, data type, and attributes that control how to use the field in the search index. Checkboxes enable or disable the following attributes:

* Retrievable: Fields returned in a query response.
* Filterable: Fields that accept a filter expression.
* Sortable: Fields that accept an orderby expression.
* Facetable: Fields used in a faceted navigation structure.
* Searchable: Fields used in full text search. Strings are searchable. Numeric fields and Boolean fields are often marked as not searchable.

####Step 05
Now we will configure the executable process and indexer name. Since we are getting started keep the default settings and select "Submit"

![step51](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jy57wai0d7i4cer3j9u4.png)

![step52](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q668m55g9oe5b8qhu0ze.png)

![step53](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5t9cpoxr8fm9felqbhxd.png)

####Step 06
Go to "Indexers" from the left hand side menu and you will see that index cration status with document count in it.

![step6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j1380vlw0cp05wmdqpdt.png)

####Step 07:
Go to "Indexes" from the left hand side menu and you will see that index document count and storage size.

![step7](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qx0duzeonj9dybkzd51w.png)

#Querying with Search explorer
####Step 01:
On the Search explorer tab, enter text to search on example: new york hotel near to Time's Square and in Chelsea neighborhood. And select "Search". You will see the result.

![query search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xots348e45qrnmhhbn4j.png)

Query output in JSON be like below. You will see that output contains search terms in it.
```
{
  "@odata.context": "https://firstaisearchservice.search.windows.net/indexes('hotels-sample-index')/$metadata#docs(*)",
  "value": [
    {
      "@search.score": 39.42806,
      "HotelId": "15",
      "HotelName": "Peaceful Market Hotel & Spa",
      "Description": "Book now and Save up to 30%.  Central location. Steps from Empire State Building & Times Square, in Chelsea neighborhood. Brand new rooms. Impeccable service.",
      "Description_fr": "Réservez dès maintenant et économisez jusqu'à 30%.  Emplacement central. A quelques pas de l'Empire State Building & Times Square, dans le quartier de Chelsea. Chambres flambant neuves. Service impeccable.",
      "Category": "Resort and Spa",
      "Tags": [
        "continental breakfast",
        "restaurant",
        "view"
      ]
}
```

####Clean up resources
It's a good idea at the end of a project to identify whether you still need the resources you created. Resources left running can cost you money. You can delete resources individually or delete the resource group to delete the entire set of resources.



####Conclusion
Overall, the purpose of using Azure AI Search is to deliver intelligent, relevant, and efficient search experiences that drive user engagement, unlock insights, and add value to applications and solutions across various industries and domains.

####Sample Dataset
[Azure AI Search Sample Data](https://github.com/Azure-Samples/azure-search-sample-data)