Azure AI Search is a cloud search service that gives developers infrastructure, APIs, and tools for building a rich search experience over private, heterogeneous content in web, mobile, and enterprise applications.
The ballarinax/azure.ai.search package offers functionality to connect and interact with Azure AI Search REST API enabling seamless integration with Azure's powerful search and indexing capabilities for building comprehensive search solutions.
To use the Azure AI Search Connector, you must have an Azure subscription and an Azure AI Search service. If you do not have an Azure account, you can sign up for one here.
-
Sign in to the Azure portal.
-
Click on "Create a resource" and search for "AI Search".
-
Select "AI Search" and click "Create".
-
Fill in the required details:
- Resource group: Select or create a new resource group
- Service name: Choose a unique name for your search service
- Location: Select a region close to your application
- Pricing tier: Choose the appropriate tier based on your needs
-
Click "Review + create" and then "Create" to provision the service.
-
Once the service is created, navigate to your Azure AI Search service in the Azure portal.
-
In the "Overview" section, note the URL (e.g.,
https://your-service.search.windows.net). -
Navigate to "Keys" in the left menu to find your admin keys.
-
Copy either the primary or secondary admin key to use in your application.
To use the Azure AI Search connector in your Ballerina application, update the .bal file as follows:
Import the ballerinax/azure.ai.search module.
import ballerinax/azure.ai.search as azureSearch;Create an azureSearch:Client with your Azure AI Search service URL and admin key.
configurable string serviceUrl = ?;
configurable string adminKey = ?;
final azureSearch:Client searchClient = check new (serviceUrl, {});Now, you can utilize available connector operations.
public function main() returns error? {
// Define a simple search index
azureSearch:SearchIndex searchIndex = {
name: "hotels",
fields: [
{
name: "id",
'type: "Edm.String",
'key: true,
searchable: false
},
{
name: "name",
'type: "Edm.String",
searchable: true,
filterable: true
}
]
};
SearchIndex response = check searchClient->indexesCreate(searchIndex, {"api-key": adminKey}, {
api\-version: "2025-09-01"
});
}bal runThe Azure AI Search connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:
- RAG ingestion - A comprehensive example demonstrating the complete Azure AI Search workflow including data source creation, index creation, indexer setup, and execution.
-
Download and install Java SE Development Kit (JDK) version 17. You can download it from either of the following sources:
Note: After installation, remember to set the
JAVA_HOMEenvironment variable to the directory where JDK was installed. -
Download and install Ballerina Swan Lake.
-
Download and install Docker.
Note: Ensure that the Docker daemon is running before executing any tests.
-
Export Github Personal access token with read package permissions as follows,
export packageUser=<Username> export packagePAT=<Personal access token>
Execute the commands below to build from the source.
-
To build the package:
./gradlew clean build
-
To run the tests:
./gradlew clean test -
To build the without the tests:
./gradlew clean build -x test -
To run tests against different environments:
./gradlew clean test -Pgroups=<Comma separated groups/test cases>
-
To debug the package with a remote debugger:
./gradlew clean build -Pdebug=<port>
-
To debug with the Ballerina language:
./gradlew clean build -PbalJavaDebug=<port>
-
Publish the generated artifacts to the local Ballerina Central repository:
./gradlew clean build -PpublishToLocalCentral=true
-
Publish the generated artifacts to the Ballerina Central repository:
./gradlew clean build -PpublishToCentral=true
As an open-source project, Ballerina welcomes contributions from the community.
For more information, go to the contribution guidelines.
All the contributors are encouraged to read the Ballerina Code of Conduct.
- For more information go to the
azure.ai.searchpackage. - For example demonstrations of the usage, go to Ballerina By Examples.
- Chat live with us via our Discord server.
- Post all technical questions on Stack Overflow with the #ballerina tag.