How to Manage Azure Cognitive Search Index using REST API

Ahamed Fazil Buhari
 
Senior Developer
February 26, 2023
 
Rate this article
 
Views
1119

The Azure Cognitive Search Index is a compelling tool that can be used to configure, create, and manage search indexes. In this article, we will explore how to manage the Azure Cognitive Search Index using the REST API. Additionally, we can use C#, Java, JavaScript, Python, PowerShell, and ARM templates to manage the index, but we will focus on the REST API in this article.

The Azure Cognitive Search Index is a key factor in Azure Cognitive Search, and it enables users to create and manage search indexes for a variety of data types. The index is a set of searchable data that is organized into fields and documents, and it can be queried later.

For demo purpose, I’ve created an Azure Cognitive Search with Free tier.

Prerequisites: Get the URL of your search service and the admin key to call REST API

url: https://<name of service>.search.windows.net

api-key: dxxxxxxx

 

Create an Index: Create an Index before loading up the data, here I created movies index. And from postman we can create the fields using REST API,

Verb: PUT
URL: https://{service-name}.search.windows.net/indexes/{index-name}?api-version={api-version}

Example: https://srch-playground-dev.search.windows.net/indexes/movies?api-version=2020-06-30

Header: api-key: dxxxxxx, Content-Type: application/json

Its important to mention the API version as query param in the URL, to find more about the versions and its specifications please refer here

And we can check the created index in Search Service under Indexes pivot

 

Importing documents to the newly created Index: Next step is to add documents into movies index (created in last step) using REST API

 

Update an Index: To update an index, we need to send a PUT request to the Azure Cognitive Search REST API (just like how we created the index). The request body contains the updated schema of the index. We can modify the field instead of deleting it or if we need to change the type or other properties like Filterable, Sortable.

Since the schema definitions are strongly typed, and existing fields cannot be removed. To make a field filterable or remove a filterable definition for a field, the entire index must be recreated and re-indexed.

Delete an Index: To delete an index, we need to send a DELETE request to the Azure Cognitive Search REST API. Here’s an example request:

https://{service-name}.search.windows.net/indexes/{index-name}?api-version={api-version}

we explored how to manage Azure Cognitive Search Index using REST API. It can help start building powerful search experiences for your applications.

 

Happy Coding,

Fazil

Author Info

Ahamed Fazil Buhari
 
Senior Developer
 
Rate this article
 
Ahamed is a Senior Developer and he has very good experience in the field of Microsoft Technologies, especially SharePoint, Azure, M365, SPFx, .NET and client side scripting - JavaScript, TypeScript, ...read more
 

Leave a comment