- Overview
- Architecture
- Features
- Tech Stack
- Quick Start
- API Endpoints
- Configuration
- Caching Strategy
- Monitoring & Observability
- Security
- Testing
- Deployment
- Contributing
- License
- Support
The SMARTDRIVE Search Service is a high-performance, intelligent search engine that provides advanced file discovery capabilities across the SMARTDRIVE ecosystem. It leverages Elasticsearch for powerful full-text search and Redis for lightning-fast caching, enabling users to find files quickly and efficiently.
- π Intelligent Search: Full-text search across file names, content, and AI-generated metadata
- π High-Performance Caching: Redis-based caching for instant search results
- π Advanced Analytics: Search analytics and insights
- π Multi-Service Integration: Seamless integration with other SMARTDRIVE services
- π Scalable Architecture: Built for high availability and performance
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Search API β β Elasticsearch β β Redis β
β (Spring Boot) βββββΊβ (Search Index)β β (Caching) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Search Logic β β Index Schema β β Cache TTL β
β & Filters β β & Mapping β β & Invalidationβ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- Search Controller: REST API endpoints for search operations
- Search Service: Core search logic and business rules
- Elasticsearch Integration: Direct querying and indexing
- Cache Manager: Redis-based caching with TTL
- Circuit Breaker: Resilience patterns for external dependencies
- Full-Text Search: Search across file names, content types, and metadata
- AI-Enhanced Search: Search through AI-generated tags, summaries, and labels
- Image Content Search: Search through image labels, objects, and extracted text
- Document Content Search: Search through extracted text and document metadata
- Advanced Filters: Filter by content type, upload date, file size, and more
- Pagination: Efficient result pagination with configurable page sizes
- Redis Caching: Intelligent caching with configurable TTL
- Search Results Cache: 15-minute TTL for repeated searches
- File Details Cache: 1-hour TTL for file metadata
- Cache Invalidation: Automatic cache cleanup on file operations
- Circuit Breaker: Resilience against Elasticsearch failures
- Search Analytics: Track search patterns and performance
- Response Time Monitoring: Monitor search response times
- Cache Hit Rates: Track cache effectiveness
- OpenTelemetry Integration: Distributed tracing and metrics
- Health Checks: Comprehensive health monitoring
- Java 17: Modern Java with enhanced performance
- Spring Boot 3.2: Rapid application development framework
- Spring Web: RESTful web services
- Spring Data Elasticsearch: Elasticsearch integration
- Spring Data Redis: Redis caching integration
- Elasticsearch 8.x: Distributed search and analytics engine
- Redis 7.x: In-memory data structure store for caching
- Spring Cache: Caching abstraction layer
- Resilience4j: Circuit breaker and resilience patterns
- OpenTelemetry: Observability framework
- Micrometer: Application metrics
- Spring Boot Actuator: Health checks and monitoring
- OpenAPI 3: API documentation
- Swagger UI: Interactive API documentation
- JUnit 5: Unit testing framework
- Testcontainers: Integration testing
- Java 17 or higher
- Docker and Docker Compose
- Elasticsearch 8.x
- Redis 7.x
-
Clone the Repository
git clone <repository-url> cd search-service
-
Environment Configuration
# Copy environment template cp .env.example .env # Configure your environment variables ELASTICSEARCH_HOST=elasticsearch ELASTICSEARCH_PORT=9200 REDIS_HOST=redis REDIS_PORT=6379
-
Start Dependencies
# Start Elasticsearch and Redis docker-compose up -d elasticsearch redis -
Run the Application
# Using Gradle ./gradlew bootRun # Or using Docker docker-compose up search-service
-
Verify Installation
# Health check curl http://localhost:8084/actuator/health # API documentation open http://localhost:8084/swagger-ui.html
POST /api/v1/search
Content-Type: application/json
{
"query": "document",
"page": 1,
"size": 10,
"filters": {
"contentType": "application/pdf",
"uploadDateFrom": "2024-01-01",
"uploadDateTo": "2024-12-31"
}
}GET /api/v1/search/files/{contentId}DELETE /api/v1/search/cache/{cacheKey}DELETE /api/v1/search/cacheDELETE /api/v1/search/cache/filesPOST /api/v1/search/cache/invalidate/uploadPOST /api/v1/search/cache/invalidate/update/{contentId}POST /api/v1/search/cache/invalidate/delete/{contentId}GET /actuator/healthGET /actuator/metricsspring:
application:
name: search-service
elasticsearch:
uris: http://elasticsearch:9200
data:
redis:
host: redis
port: 6379
timeout: 2000ms
lettuce:
pool:
max-active: 8
max-idle: 8
min-idle: 0
app:
elasticsearch:
index-name: file_metadata
cache:
ttl:
search-results: 900 # 15 minutes
file-details: 3600 # 1 hour
management:
endpoints:
web:
exposure:
include: health,metrics,info
endpoint:
health:
show-details: always| Variable | Description | Default |
|---|---|---|
ELASTICSEARCH_HOST |
Elasticsearch host | elasticsearch |
ELASTICSEARCH_PORT |
Elasticsearch port | 9200 |
REDIS_HOST |
Redis host | redis |
REDIS_PORT |
Redis port | 6379 |
APP_CACHE_TTL_SEARCH_RESULTS |
Search cache TTL (seconds) | 900 |
APP_CACHE_TTL_FILE_DETAILS |
File cache TTL (seconds) | 3600 |
-
Search Results Cache
- TTL: 15 minutes
- Key:
query:page:size - Purpose: Cache repeated search queries
-
File Details Cache
- TTL: 1 hour
- Key:
contentId - Purpose: Cache individual file metadata
- File Upload: Invalidates all search cache
- File Update: Invalidates search cache and specific file cache
- File Delete: Invalidates search cache and specific file cache
- Manual Invalidation: Admin endpoints for cache management
@Configuration
@EnableCaching
public class CacheConfig {
@Bean
public CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
// Configure TTL and serialization
// Handle Java 8 time types
// Enable polymorphic deserialization
}
}- Distributed Tracing: Track requests across services
- Metrics Collection: Application and business metrics
- Log Correlation: Link logs with trace IDs
- Elasticsearch Health: Connection and index status
- Redis Health: Connection and memory status
- Application Health: Overall service status
- Search Performance: Response times and throughput
- Cache Metrics: Hit rates and eviction rates
- Error Rates: Failed searches and exceptions
- Input Validation: Comprehensive request validation
- Rate Limiting: Protect against abuse
- CORS Configuration: Cross-origin resource sharing
- Error Handling: Secure error responses
- Elasticsearch Security: TLS encryption and authentication
- Redis Security: Network isolation and authentication
- Sensitive Data: No storage of sensitive information
# Run unit tests
./gradlew test
# Run with coverage
./gradlew test jacocoTestReport# Run integration tests
./gradlew integrationTest# Test search functionality
curl -X POST http://localhost:8084/api/v1/search \
-H "Content-Type: application/json" \
-d '{"query": "test", "page": 1, "size": 10}'# Build Docker image
docker build -t smartdrive-search-service .
# Run container
docker run -p 8084:8084 \
-e ELASTICSEARCH_HOST=elasticsearch \
-e REDIS_HOST=redis \
smartdrive-search-serviceapiVersion: apps/v1
kind: Deployment
metadata:
name: search-service
spec:
replicas: 3
selector:
matchLabels:
app: search-service
template:
metadata:
labels:
app: search-service
spec:
containers:
- name: search-service
image: smartdrive/search-service:latest
ports:
- containerPort: 8084
env:
- name: ELASTICSEARCH_HOST
value: "elasticsearch"
- name: REDIS_HOST
value: "redis"- High Availability: Multiple replicas across zones
- Auto-scaling: Horizontal pod autoscaling
- Resource Limits: CPU and memory constraints
- Monitoring: Prometheus and Grafana integration
- Logging: Centralized log aggregation
We welcome contributions to the SMARTDRIVE Search Service! Please follow these guidelines:
- Fork the Repository
- Create a Feature Branch:
git checkout -b feature/amazing-feature - Make Your Changes: Follow coding standards and add tests
- Run Tests: Ensure all tests pass
- Submit a Pull Request: Provide clear description and context
- Java Code Style: Follow Google Java Style Guide
- Documentation: Update README and API docs
- Testing: Maintain >80% code coverage
- Security: Follow security best practices
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Check this README and API docs
- Issues: Report bugs and feature requests on GitHub
- Discussions: Join community discussions
- Email: support@smartdrive.com
- GitHub: SMARTDRIVE Search Service
- Discord: Join our community server
- Blog: Latest updates and tutorials
Empowering intelligent file management and discovery