Troubleshooting
Common issues and solutions for the Typesense Search Plugin.
Common Issues
Search Not Working
Problem: Search returns no results or errors.
Possible Causes & Solutions:
Typesense not running
bash# Check if Typesense is running curl http://localhost:8108/health
Solution: Start Typesense
bashdocker-compose up -d # or docker run -p 8108:8108 -v $(pwd)/typesense-data:/data typesense/typesense:0.25.2 --data-dir /data --api-key=xyz --enable-cors
Wrong API key
typescript// Check your configuration typesense: { apiKey: 'xyz', // Must match Typesense startup nodes: [{ host: 'localhost', port: 8108, protocol: 'http' }] }
Collection not configured
typescript// Ensure collection is enabled collections: { posts: { enabled: true, // Must be true searchFields: ['title', 'content'] // Must have search fields } }
No data synced
typescript// Check if data exists in Typesense const client = new TypesenseClient({ nodes: [{ host: 'localhost', port: 8108, protocol: 'http' }], apiKey: 'xyz', }) const collections = await client.collections().retrieve() console.log('Collections:', collections)
No Results Returned
Problem: Search queries return empty results.
Solutions:
Check collection configuration
typescript// Verify collection is properly configured collections: { posts: { enabled: true, searchFields: ['title', 'content'], // These fields must exist facetFields: ['category', 'status'] } }
Verify data exists
typescript// Check if documents exist const searchResult = await client.collections('posts').documents().search({ q: '*', per_page: 1, }) console.log('Document count:', searchResult.found)
Check search fields
typescript// Ensure search fields contain data const documents = await client.collections('posts').documents().retrieve() console.log('Sample document:', documents[0])
Try different search terms
typescript// Test with simple queries const result = await client.collections('posts').documents().search({ q: 'test', // Simple query per_page: 10, })
Slow Search Performance
Problem: Search is slow or times out.
Solutions:
Check Typesense performance
bash# Monitor Typesense metrics curl http://localhost:8108/metrics
Optimize search parameters
typescript// Use search parameters in API calls const searchParams = { q: 'search query', per_page: 10, // Limit results num_typos: 1, // Reduce typos snippet_threshold: 30, }
Check network latency
typescript// Test connection speed const start = Date.now() await client.health.retrieve() console.log('Connection time:', Date.now() - start, 'ms')
Enable caching
typescript// Caching is enabled by default settings: { cache: { ttl: 300000, // 5 minutes in milliseconds maxSize: 1000 } }
CORS Errors
Problem: Browser CORS errors when searching.
Solutions:
Enable CORS in Typesense
bash# Start Typesense with CORS enabled docker run -p 8108:8108 \ -v $(pwd)/typesense-data:/data \ typesense/typesense:0.25.2 \ --data-dir /data \ --api-key=xyz \ --enable-cors
Check API endpoint accessibility
bash# Test API endpoint curl -H "Origin: http://localhost:3000" \ -H "Access-Control-Request-Method: GET" \ -H "Access-Control-Request-Headers: X-Requested-With" \ -X OPTIONS \ http://localhost:3000/api/search
Verify baseUrl configuration
typescript<HeadlessSearchInput baseUrl="http://localhost:3000" // Must match your domain collection="posts" />
TypeScript Errors
Problem: TypeScript compilation errors.
Solutions:
Install types
bashpnpm add -D @types/node @types/react
Check import paths
typescript// Correct import import { HeadlessSearchInput } from 'typesense-search-plugin' // Not import { HeadlessSearchInput } from 'typesense-search-plugin/dist'
Update TypeScript configuration
json// tsconfig.json { "compilerOptions": { "moduleResolution": "node", "esModuleInterop": true, "allowSyntheticDefaultImports": true } }
Debug Mode
Enable debug logging to troubleshoot issues:
// Enable debug mode
const debugSearch = async () => {
console.log('🔍 Debug: Starting search...')
try {
// Test Typesense connection
const health = await client.health.retrieve()
console.log('✅ Typesense health:', health)
// Test collections
const collections = await client.collections().retrieve()
console.log('📚 Collections:', collections)
// Test search
const result = await client.collections('posts').documents().search({
q: 'test',
per_page: 1,
})
console.log('🔍 Search result:', result)
} catch (error) {
console.error('❌ Search error:', error)
}
}
Environment-Specific Issues
Development
Common issues:
- Typesense not running
- Wrong API keys
- CORS issues
- Missing environment variables
Solutions:
# Check environment
echo $TYPESENSE_API_KEY
echo $TYPESENSE_NODES
# Start services
docker-compose up -d
pnpm dev
Production
Common issues:
- Network connectivity
- SSL/TLS issues
- Performance problems
- Memory issues
Solutions:
// Production configuration
typesense: {
apiKey: process.env.TYPESENSE_API_KEY,
nodes: JSON.parse(process.env.TYPESENSE_NODES),
connectionTimeoutSeconds: 10,
numRetries: 5
}
Performance Issues
Memory Usage
Problem: High memory usage.
Solutions:
- Limit result sets
- Enable pagination
- Use virtual scrolling
- Implement result caching
Slow Queries
Problem: Queries take too long.
Solutions:
- Optimize search fields
- Reduce typo tolerance
- Limit facets
- Use field boosting
Getting Help
Before Asking for Help
Check the logs
bash# Check Payload logs tail -f logs/payload.log # Check Typesense logs docker logs typesense-container
Test with minimal configuration
typescript// Minimal working example typesenseSearch({ typesense: { apiKey: 'xyz', nodes: [{ host: 'localhost', port: 8108, protocol: 'http' }], }, collections: { posts: { enabled: true, searchFields: ['title'], }, }, })
Check versions
bash# Check package versions pnpm list typesense-search-plugin pnpm list typesense pnpm list payload
Reporting Issues
When reporting issues, include:
Environment details
- Node.js version
- Package versions
- Operating system
Configuration
- Your Payload config
- Typesense configuration
- Error messages
Steps to reproduce
- What you did
- What you expected
- What actually happened
Logs and errors
- Console output
- Network requests
- Stack traces
Community Support
Quick Fixes
Reset Everything
# Stop all services
docker-compose down
# Clear Typesense data
rm -rf typesense-data
# Restart everything
docker-compose up -d
pnpm dev
Update Configuration
// Reset to default configuration
typesenseSearch({
typesense: {
apiKey: 'xyz',
nodes: [{ host: 'localhost', port: 8108, protocol: 'http' }],
},
collections: {
// Add your collections here
},
})
Clear Cache
# Clear npm cache
pnpm store prune
# Clear build cache
rm -rf .next
rm -rf dist
# Reinstall dependencies
rm -rf node_modules
pnpm install