Skip to content

Module 8: Search Explorer & Portal Tools - Code Samples

This directory contains comprehensive code samples demonstrating how to replicate Azure AI Search portal functionality programmatically.

Overview

The Azure portal provides powerful tools for working with Azure AI Search, including Search Explorer for testing queries, Import Data wizard for automated indexing, and various management interfaces. These code samples show how to achieve the same functionality using REST APIs and SDKs.

Directory Structure

code-samples/
├── notebooks/                          # Jupyter notebooks for interactive learning
│   ├── 01_search_explorer_basics.ipynb
│   ├── 02_import_data_wizard.ipynb
│   └── 03_portal_management_monitoring.ipynb
├── rest/                               # REST API examples
│   ├── 01_search_explorer_queries.http
│   ├── 02_import_data_wizard_operations.http
│   └── 03_portal_management_operations.http
├── csharp/                             # C# SDK examples
│   ├── 01_SearchExplorerEquivalent.cs
│   └── 02_ImportDataWizardEquivalent.cs
├── javascript/                         # JavaScript/Node.js SDK examples
│   ├── 01_search_explorer_equivalent.js
│   └── 02_import_data_wizard_equivalent.js
├── python/                             # Python SDK examples (to be added)
└── README.md                           # This file

Prerequisites

Before running these samples, ensure you have:

  1. Azure AI Search Service
  2. Basic tier or higher recommended
  3. Admin API key for management operations
  4. Query API key for search operations

  5. Sample Data

  6. Hotels sample index (recommended)
  7. Or your own data source (Azure Blob Storage, SQL Database, etc.)

  8. Development Environment

  9. For notebooks: Jupyter, Python 3.8+, required packages
  10. For REST: VS Code with REST Client extension or Postman
  11. For C#: .NET 6.0+, Azure.Search.Documents NuGet package
  12. For JavaScript: Node.js 14+, @azure/search-documents npm package

Configuration

Update the following configuration values in each sample:

SEARCH_SERVICE_NAME = "your-search-service-name"
SEARCH_API_KEY = "your-admin-api-key"
INDEX_NAME = "hotels-sample"  # or your index name
API_VERSION = "2023-11-01"

For Import Data Wizard samples, also configure:

STORAGE_CONNECTION_STRING = "your-storage-connection-string"
CONTAINER_NAME = "your-container-name"
COGNITIVE_SERVICES_KEY = "your-cognitive-services-key"  # optional

Sample Categories

1. Search Explorer Equivalent

Purpose: Replicate Search Explorer functionality for testing and debugging queries.

Features Demonstrated: - Basic text search - Advanced search with filtering and sorting - Faceted search - Hit highlighting - Full Lucene query syntax - Suggestions and autocomplete - Performance testing - Query export and sharing

Files: - notebooks/01_search_explorer_basics.ipynb - rest/01_search_explorer_queries.http - csharp/01_SearchExplorerEquivalent.cs - javascript/01_search_explorer_equivalent.js

2. Import Data Wizard Equivalent

Purpose: Automate the complete Import Data Wizard workflow programmatically.

Features Demonstrated: - Data source creation (Azure Blob, SQL, Cosmos DB) - Skillset creation with AI enrichment - Index schema generation - Indexer configuration and execution - Monitoring and validation - Error handling and troubleshooting

Files: - notebooks/02_import_data_wizard.ipynb - rest/02_import_data_wizard_operations.http - csharp/02_ImportDataWizardEquivalent.cs - javascript/02_import_data_wizard_equivalent.js

3. Portal Management & Monitoring

Purpose: Implement portal management and monitoring features programmatically.

Features Demonstrated: - Service statistics and health monitoring - Index management and statistics - Indexer execution monitoring - Data source management - Performance analytics - Quota and usage monitoring - Automated health checks - Operational reporting

Files: - notebooks/03_portal_management_monitoring.ipynb - rest/03_portal_management_operations.http

Quick Start Guide

# Install required packages
pip install azure-search-documents pandas matplotlib seaborn requests

# Start Jupyter
jupyter notebook

# Open and run notebooks in order:
# 1. 01_search_explorer_basics.ipynb
# 2. 02_import_data_wizard.ipynb
# 3. 03_portal_management_monitoring.ipynb

2. Using REST API

# Install VS Code REST Client extension
# Open .http files in VS Code
# Update configuration variables
# Execute requests using Ctrl+Alt+R (or Cmd+Alt+R on Mac)

3. Using C# SDK

# Create new console application
dotnet new console -n AzureSearchPortalTools
cd AzureSearchPortalTools

# Add required packages
dotnet add package Azure.Search.Documents

# Copy sample code and update configuration
# Run the application
dotnet run

4. Using JavaScript SDK

# Initialize Node.js project
npm init -y

# Install required packages
npm install @azure/search-documents

# Copy sample code and update configuration
# Run the application
node 01_search_explorer_equivalent.js

Key Features by Sample

Search Explorer Features

Feature Description Notebook REST C# JS
Basic Search Simple text queries
Advanced Search Filtering, sorting, field selection
Faceted Search Navigation and filtering
Hit Highlighting Search term highlighting
Lucene Queries Full Lucene syntax support
Suggestions Autocomplete functionality
Performance Testing Query timing and optimization
URL Generation Shareable Search Explorer URLs
Code Export Export queries as code

Import Data Wizard Features

Feature Description Notebook REST C# JS
Data Source Creation Azure Blob, SQL, Cosmos DB
Skillset Creation AI enrichment pipeline
Index Creation Schema generation
Indexer Creation Data processing pipeline
Execution Monitoring Real-time status tracking
Error Handling Failure detection and reporting
Validation Result verification
Cleanup Resource management

Portal Management Features

Feature Description Notebook REST C# JS
Service Statistics Resource usage and quotas
Index Management CRUD operations and stats
Indexer Monitoring Execution history and status
Data Source Management Connection testing and config
Performance Analytics Metrics and visualization
Health Checks Automated monitoring
Reporting Operational dashboards

Best Practices

1. Development Workflow

  1. Start with Portal - Use Azure portal for initial exploration
  2. Prototype with Notebooks - Interactive development and testing
  3. Implement with SDKs - Production-ready code
  4. Automate with REST - CI/CD integration

2. Query Development

  1. Begin Simple - Start with basic text searches
  2. Add Complexity Gradually - Filters, facets, sorting
  3. Test Edge Cases - Empty results, special characters
  4. Optimize Performance - Monitor query times
  5. Document Patterns - Save working query examples

3. Import Data Wizard Usage

  1. Use for Prototyping - Quick setup and testing
  2. Export Configurations - Save for programmatic use
  3. Monitor Costs - Especially AI enrichment
  4. Test Incrementally - Validate each step
  5. Plan for Scale - Consider performance implications

4. Portal Management

  1. Implement Health Checks - Proactive monitoring
  2. Set Up Alerts - Quota thresholds and failures
  3. Monitor Performance - Query latency and throughput
  4. Track Costs - Resource usage and optimization
  5. Automate Operations - Reduce manual tasks

Troubleshooting

Common Issues

  1. Authentication Errors
  2. Verify API key is correct and has appropriate permissions
  3. Check service name and endpoint URL

  4. Index Not Found

  5. Ensure index exists and name is correct
  6. Verify you have access to the index

  7. Query Syntax Errors

  8. Check for proper escaping of special characters
  9. Validate field names exist in index schema

  10. Indexer Failures

  11. Review indexer execution history
  12. Check data source connectivity
  13. Validate field mappings

  14. Performance Issues

  15. Monitor query complexity and response times
  16. Check service tier and scaling limits
  17. Optimize index schema and queries

Getting Help

  1. Azure Documentation: Azure AI Search Documentation
  2. REST API Reference: Azure AI Search REST API
  3. SDK Documentation:
  4. .NET SDK
  5. JavaScript SDK
  6. Community Support: Microsoft Q&A

Contributing

To contribute to these samples:

  1. Fork the repository
  2. Create a feature branch
  3. Add or improve samples
  4. Test thoroughly
  5. Submit a pull request

License

These samples are provided under the MIT License. See LICENSE file for details.

Next Steps

After completing these samples:

  1. Explore Advanced Features - Vector search, semantic search
  2. Build Production Applications - Implement search UIs
  3. Set Up Monitoring - Production monitoring and alerting
  4. Optimize Performance - Query tuning and scaling
  5. Integrate with DevOps - CI/CD pipelines and automation
  • Module 7: Pagination & Result Shaping
  • Module 9: Advanced Query Techniques (Intermediate)
  • Module 10: Performance Optimization (Intermediate)