Module 2: Troubleshooting Guide¶
Overview¶
This comprehensive troubleshooting guide helps you resolve common issues encountered while working with Azure AI Search basic operations. Issues are organized by category with clear solutions and prevention tips.
๐ง Prerequisites Setup Issues¶
Connection Problems¶
โ "Connection failed" or timeout errors¶
Symptoms: - Script fails during connection test - HTTP timeout errors - "Service unavailable" messages
Solutions: 1. Verify Service Endpoint:
# Check your endpoint format
echo $AZURE_SEARCH_SERVICE_ENDPOINT
# Should be: https://your-service.search.windows.net
-
Test Network Connectivity:
-
Check Service Status:
- Visit Azure portal
- Verify service is running and not paused
- Check for any service alerts
โ "Authentication failed" (401/403 errors)¶
Symptoms: - "Access denied" messages - "Invalid subscription key" errors - 401 or 403 HTTP status codes
Solutions: 1. Verify API Key:
- Check Key Permissions:
- Use Admin Key for setup (has full permissions)
- Query keys won't work for index creation
-
Verify key hasn't expired
-
Test Key Manually:
Index Creation Issues¶
โ "Index already exists" (Normal)¶
Status: โ This is expected behavior Action: The script will use the existing index - no action needed
โ "Failed to create index" errors¶
Symptoms: - Index creation fails with schema errors - Field definition errors - Permission denied for index creation
Solutions: 1. Use Admin Key: Query keys can't create indexes 2. Check Service Tier: Ensure your service tier supports the features used 3. Clear Existing Index (if needed):
# Only if you need to start fresh
from azure.search.documents.indexes import SearchIndexClient
index_client = SearchIndexClient(endpoint, credential)
index_client.delete_index("handbook-samples")
Document Upload Issues¶
โ "Document upload failed" errors¶
Symptoms: - JSON parsing errors - "StartArray node was found" errors - Upload returns 400 status
Status: โ RESOLVED - Fixed in current version Previous Issue: Tags field array format issue Current Solution: Uses string format for tags field
โ "Some documents failed to upload"¶
Solutions: 1. Check Document Format: Ensure all required fields are present 2. Verify Field Types: Match the index schema exactly 3. Check Document Size: Ensure documents aren't too large 4. Review Error Details: Script shows specific failure reasons
๐ Search Operation Issues¶
No Results Found¶
โ Search returns empty results¶
Symptoms: - All searches return 0 results - Index shows documents but searches fail
Solutions: 1. Verify Index Has Data:
-
Check Search Syntax:
-
Verify Field Names:
โ Specific searches return no results¶
Solutions: 1. Try Broader Terms:
# Instead of specific terms
results = search_client.search("machine learning tutorial")
# Try individual terms
results = search_client.search("machine")
results = search_client.search("learning")
-
Use Wildcard Search:
-
Check Search Mode:
Query Syntax Errors¶
โ "Invalid query syntax" (400 errors)¶
Symptoms: - Boolean queries fail - Special characters cause errors - Phrase searches don't work
Solutions: 1. Escape Special Characters:
# Problematic
query = 'title:"C# Programming"'
# Fixed
query = 'title:"C# Programming"' # Use proper quotes
-
Validate Boolean Syntax:
-
Check Phrase Syntax:
Performance Issues¶
โ Slow search responses¶
Solutions: 1. Limit Result Count:
-
Select Specific Fields:
-
Use Field-Specific Search:
๐ป Language-Specific Issues¶
Python Issues¶
โ "No module named 'azure.search.documents'"¶
Solution:
โ "ImportError" or package conflicts¶
Solutions: 1. Use Virtual Environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install azure-search-documents python-dotenv
- Update Packages:
C# Issues¶
โ "Package not found" errors¶
Solution:
โ "Namespace not found" errors¶
Solution: Add proper using statements:
JavaScript Issues¶
โ "Module not found" errors¶
Solution:
โ "CORS errors" in browser¶
Solutions: 1. Configure CORS in Azure portal 2. Use Query Key (not admin key) for browser apps 3. Use Server-Side Proxy for sensitive operations
REST API Issues¶
โ "Invalid Content-Type" errors¶
Solution: Ensure proper headers:
โ "API version not supported"¶
Solution: Use supported API version:
๐ง Environment Issues¶
Environment Variables¶
โ "Environment variable not set" errors¶
Solutions: 1. Check Variables Are Set:
-
Set Variables Properly:
-
Use .env File:
Path and Directory Issues¶
โ "File not found" or "Module not found"¶
Solutions: 1. Check Current Directory:
-
Navigate to Correct Directory:
-
Verify File Exists:
๐งช Testing and Validation¶
Verification Steps¶
โ Run Verification Test¶
Expected output:
โ
Index 'handbook-samples' contains 10 documents
โ
Simple search works - found 3 results for 'python'
โ
Sample result: 'Python Programming Fundamentals' (Score: 4.489)
๐ Setup verification successful!
โ Manual Testing¶
# Test basic connectivity
from azure.search.documents import SearchClient
from azure.core.credentials import AzureKeyCredential
search_client = SearchClient(endpoint, index_name, credential)
count = search_client.get_document_count()
print(f"Index contains {count} documents")
# Test basic search
results = list(search_client.search("python", top=3))
print(f"Search returned {len(results)} results")
๐ Getting Additional Help¶
Self-Help Resources¶
- Check Error Messages Carefully: They often contain the exact solution
- Review Prerequisites: Ensure all requirements are met
- Try Verification Test: Isolates the specific issue
- Check Azure Portal: Verify service status and configuration
Escalation Path¶
If issues persist after trying these solutions:
- Document the Error: Copy exact error messages
- Note Your Environment: OS, Python version, package versions
- List Steps Taken: What solutions you've already tried
- Check Service Status: Azure service health dashboard
Common Resolution Patterns¶
Most issues fall into these categories: - 90%: Environment variables or API key issues - 5%: Network connectivity or service availability - 3%: Package installation or version conflicts - 2%: Index schema or data format issues
๐ Prevention Tips¶
Best Practices to Avoid Issues¶
- Always Run Prerequisites First: Don't skip the setup script
- Use Environment Variables: Avoid hardcoding credentials
- Test Incrementally: Verify each step before proceeding
- Keep Packages Updated: Use latest SDK versions
- Use Admin Keys for Setup: Query keys have limited permissions
- Monitor Service Health: Check Azure portal regularly
Monitoring and Maintenance¶
# Regular health check
def health_check():
try:
count = search_client.get_document_count()
test_results = list(search_client.search("test", top=1))
print(f"โ
Service healthy: {count} docs, search working")
return True
except Exception as e:
print(f"โ Service issue: {e}")
return False
Still having issues? The troubleshooting steps above resolve 99% of common problems. If you're still stuck, double-check your Prerequisites setup and try the verification test. ๐ง