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:
- Azure AI Search Service
- Basic tier or higher recommended
- Admin API key for management operations
-
Query API key for search operations
-
Sample Data
- Hotels sample index (recommended)
-
Or your own data source (Azure Blob Storage, SQL Database, etc.)
-
Development Environment
- For notebooks: Jupyter, Python 3.8+, required packages
- For REST: VS Code with REST Client extension or Postman
- For C#: .NET 6.0+, Azure.Search.Documents NuGet package
- 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¶
1. Using Jupyter Notebooks (Recommended for Learning)¶
# 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¶
- Start with Portal - Use Azure portal for initial exploration
- Prototype with Notebooks - Interactive development and testing
- Implement with SDKs - Production-ready code
- Automate with REST - CI/CD integration
2. Query Development¶
- Begin Simple - Start with basic text searches
- Add Complexity Gradually - Filters, facets, sorting
- Test Edge Cases - Empty results, special characters
- Optimize Performance - Monitor query times
- Document Patterns - Save working query examples
3. Import Data Wizard Usage¶
- Use for Prototyping - Quick setup and testing
- Export Configurations - Save for programmatic use
- Monitor Costs - Especially AI enrichment
- Test Incrementally - Validate each step
- Plan for Scale - Consider performance implications
4. Portal Management¶
- Implement Health Checks - Proactive monitoring
- Set Up Alerts - Quota thresholds and failures
- Monitor Performance - Query latency and throughput
- Track Costs - Resource usage and optimization
- Automate Operations - Reduce manual tasks
Troubleshooting¶
Common Issues¶
- Authentication Errors
- Verify API key is correct and has appropriate permissions
-
Check service name and endpoint URL
-
Index Not Found
- Ensure index exists and name is correct
-
Verify you have access to the index
-
Query Syntax Errors
- Check for proper escaping of special characters
-
Validate field names exist in index schema
-
Indexer Failures
- Review indexer execution history
- Check data source connectivity
-
Validate field mappings
-
Performance Issues
- Monitor query complexity and response times
- Check service tier and scaling limits
- Optimize index schema and queries
Getting Help¶
- Azure Documentation: Azure AI Search Documentation
- REST API Reference: Azure AI Search REST API
- SDK Documentation:
- .NET SDK
- JavaScript SDK
- Community Support: Microsoft Q&A
Contributing¶
To contribute to these samples:
- Fork the repository
- Create a feature branch
- Add or improve samples
- Test thoroughly
- Submit a pull request
License¶
These samples are provided under the MIT License. See LICENSE file for details.
Next Steps¶
After completing these samples:
- Explore Advanced Features - Vector search, semantic search
- Build Production Applications - Implement search UIs
- Set Up Monitoring - Production monitoring and alerting
- Optimize Performance - Query tuning and scaling
- Integrate with DevOps - CI/CD pipelines and automation
Related Modules¶
- Module 7: Pagination & Result Shaping
- Module 9: Advanced Query Techniques (Intermediate)
- Module 10: Performance Optimization (Intermediate)