Saturday, October 24, 2020

Azure Cognitive Search

Azure Search is a managed service running in the public cloud. A development team can create a new instance of the service, then start using it right away. The team doesn’t need to install or manage its own search technology. Azure Search is intended to provide developers with complex search capabilities for mobile and web development while hiding infrastructure requirements and search algorithm complexities. Azure Search is a recent addition to Microsoft's Infrastructure as a Service (IaaS) approach.

Azure Search is an API based service that provides REST APIs via protocols such as OData or integrated libraries such as the .NET SDK. Primarily the service consists of the creation of data indexes and search requests within the index.

How to use Azure search

We will create a demo application in which will use azure search and explain how it works. In demo application we are using some of azure services

1.       Blob Storage

2.       Azure Search

3.       Azure Maps

4.       Web App

Demo application architecture will look like as below

Blob Storage

We will use already created storage account djblogsstorageaccount to save JSON file in blob. If you want to read more about storage account, you can read my previous blog What is Azure Storage Account?

Need follow steps to create container inside already created storage account.

1.       Go to azure portal

2.       Once we login in portal select the djblogsstorageaccount storage account.

3.       Add new hotelsjson container inside blob containers to save JSON files inside it.

4.       Once hotelsjson container is added. Now we will upload JSON file which have all the hotel information.

5.       Now hotels data uploaded in blob container and azure search will use it.

Azure Search

If you want to use azure search service then first you need to create a new instance service, then start using it right away.

How it works

When you create a Cognitive Search service, you get a search engine that performs indexing and query execution, persistent storage of indexes that you create and manage, and a query language for composing simple to complex queries. Optionally, a search service integrates with other Azure services in the form of indexers that automate data ingestion/retrieval from Azure data sources, and skillsets that incorporate consumable AI from Cognitive Services, such as image and text analysis, or custom AI that you create in Azure Machine Learning or wrap inside Azure Functions.

Architecturally, a search service sits in between the external data stores that contain your un-indexed data, and a client app that sends query requests to a search index and handles the response. An index schema determines the structure of searchable content.

The two primary workloads of a search service are indexing and querying.

1.       Indexing brings text into to your search service and makes it searchable. Internally, inbound text is processed into tokens and stored in inverted indexes for fast scans. During indexing, you have the option of adding cognitive skills, either predefined ones from Microsoft or custom skills that you create. The subsequent analysis and transformations can result in new information and structures that did not previously exist, providing high utility for many search and knowledge mining scenarios.

2.       Once an index is populated with searchable data, your client app sends query requests to a search service and handles responses. All query execution is over a search index that you create, own, and store in your service. In your client app, the search experience is defined using APIs from Azure Cognitive Search, and can include relevance tuning, autocomplete, synonym matching, fuzzy matching, pattern matching, filter, and sort.

How to create Azure search service

Need follow steps to create azure search service.

1.       Go to azure portal

2.       Once we login in portal then need to create Azure Cognitive Search.


3.       Once we click on create button it will open form like below

4.       As above I am choosing free pricing tier for demo. Once we fill all the information click on Review + Create button it will create azure search for us. It will look like below

5.       Azure search service created. We can consume it with help of service URL and Keys as below.


6.       Once service instance is created then need to import data into service instance. Azure provide multiple data provider to import data into azure search as below. We will use azure storage where our hotels JSON stored.


7.       Once we click on Azure Blob Storage. It will ask to select storage account as below

8.   To get started, an application must first create one or more indexes into data. Each index contains information that a search request can access, and it’s the fundamental data store of Azure Search. Once an index exists, the application can begin issuing searches against it and displaying the results. Finally, the application must periodically update the index as the data it searches on changes.

           Getting an index ready to use requires two things:

a.       Defining the index’s schema, including specifying the fields it contains and setting various attributes for each field.

b.       Populating the index by supplying its initial set of data. Most often, this data will come from the application’s operational database, but this isn’t required. An index can also hold data from other sources.

Field attributes determine how a field is used, such as whether it is used in full text search, faceted navigation, sort operations, and so forth.String fields are often marked as "Searchable" and "Retrievable". Fields used to narrow search results include "Sortable", "Filterable", and "Facetable".




Full-text searchable, subject to lexical analysis such as word-breaking during indexing. If you set a searchable field to a value like "sunny day", internally it will be split into the individual tokens "sunny" and "day". For details, see How full text search works.


Referenced in $filter queries. Filterable fields of type Edm.String or Collection(Edm.String) do not undergo word-breaking, so comparisons are for exact matches only. For example, if you set such a field f to "sunny day", $filter=f eq 'sunny' will find no matches, but $filter=f eq 'sunny day' will.


By default the system sorts results by score, but you can configure sort based on fields in the documents. Fields of type Collection(Edm.String) cannot be "sortable".


Typically used in a presentation of search results that includes a hit count by category (for example, hotels in a specific city). This option cannot be used with fields of type Edm.GeographyPoint. Fields of type Edm.String that are filterable, "sortable", or "facetable" can be at most 32 kilobytes in length. For details, see Create Index (REST API).


Unique identifier for documents within the index. Exactly one field must be chosen as the key field and it must be of type Edm.String.


Determines whether the field can be returned in a search result. This is useful when you want to use a field (such as profit margin) as a filter, sorting, or scoring mechanism, but do not want the field to be visible to the end user. This attribute must be true for key fields.

It will look like as below

9.       Now indexes created in data. We can test within azure portal with help of Search explorer. It looks like as below.


10.  Once an index has been created and populated with data, users can begin issuing searches. Below figure shows how the search process looks in our own web app.

Azure Maps

Azure Maps is a collection of geospatial services and SDKs that use fresh mapping data to provide geographic context to web and mobile applications.

Azure Maps provides

1.       REST APIs to render vector and raster maps in multiple styles and satellite imagery.

2.       Creator services to create and render maps based on private indoor map data.

3.       Search services to locate addresses, places, and points of interest around the world.

4.       Various routing options; such as point-to-point, multipoint, multipoint optimization, isochrone, electric vehicle, commercial vehicle, traffic influenced, and matrix routing.

5.       Traffic flow view and incidents view, for applications that require real-time traffic information.


In this demo we will use Azure map to show the location of hotel into map. To use maps than need to create Azure Map service with help of azure portal.

Need follow steps to create Azure Maps.

1.       Go to azure portal


2.       Create Azure Maps

3.       Click on create button it will open form that need to be fill

4.       Once we click on create button. it creates azure map service for us. We consume this service with help of client key and other keys. To show hotel in map, I have used primary key as below screen.

Web App

Now our azure search service and azure map ready to consume. We need to create WebApp to consume azure search service. If you want to learn more about WebApp. Please read my previous post Create Web App

Need follow steps to create Web App.

5.       Go to azure portal


6.       Created djblogshotels webapp

7.       Download web app publisher and publish .net core MVC application from visual studio

8.       You can download DJBlogs.Azure.Search from my GitHub repository.


9.       Once code is published it will look like as below


Hope it will help you to understand azure search and map service.

Keep sharing keep learning. Cheers

No comments:

Post a Comment