A powerful Node.js microservice providing advanced search functionality using Elasticsearch with JWT authentication, complex query building capabilities, and RESTful API.
- Advanced Search Engine: Complex query builder with support for multiple operators and nested conditions
- JWT Authentication: Secure token-based authentication with RS256 algorithm
- Multi-Index Search: Search across multiple Elasticsearch indices simultaneously
- User-Scoped Queries: Save and manage personalized search queries
- RESTful API: Clean, well-documented API following OpenAPI 3.0 specification
- Docker Support: Containerized deployment with Docker
- Real-time Health Monitoring: Built-in health check endpoints
- Comprehensive Logging: Winston-based logging system
Before running the Ingenium Search Server, ensure you have the following installed:
- Node.js (v14.0.0 or later)
- npm (v6.0.0 or later)
- Elasticsearch (v8.x recommended)
- Docker (optional, for containerized deployment)
git clone https://github.com/OpenIngenium/search_server.git
cd search_servernpm installCreate a .env file in the project root with the following variables:
# Server Configuration
PORT=3025
API_VERSION=v1
# JWT Configuration
PUBLIC_PEM="-----BEGIN PUBLIC KEY-----
YOUR_PUBLIC_KEY_HERE # TODO: Replace with your actual JWT public key
-----END PUBLIC KEY-----"
# Elasticsearch Configuration
ELASTIC_SEARCH_HOST=http://localhost:9200
# Index Configuration (optional)
INDEX_MAPPING_TOTAL_FIELDS_LIMIT=20000
INDEX_MAX_RESULT_WINDOW=20000000npm run devnpm startdocker build -t ingenium-search-server .
docker run -p 3025:3025 --env-file .env ingenium-search-serverGET /api/v1/health- Check service health status
GET /api/v1/querybuilders- Get all saved queries for authenticated userGET /api/v1/querybuilders/{id}- Get specific query by IDPOST /api/v1/querybuilders- Save new search queryDELETE /api/v1/querybuilders/{id}- Delete saved query
POST /api/v1/search- Execute complex search queries
Once the server is running, you can access the interactive API documentation at:
http://localhost:3025/api-docs # TODO: Update port if you change default PORT
The API follows OpenAPI 3.0 specification and includes:
- Request/response schemas
- Authentication requirements
- Example payloads
- Interactive testing interface
| Variable | Description | Default | Required |
|---|---|---|---|
PORT |
Server port | 3025 |
No |
API_VERSION |
API version | v1 |
No |
PUBLIC_PEM |
JWT public key for token verification | "" |
Yes |
ELASTIC_SEARCH_HOST |
Elasticsearch connection URL | http://127.0.0.1:19200 |
No |
INDEX_MAPPING_TOTAL_FIELDS_LIMIT |
Elasticsearch field limit | 20000 |
No |
INDEX_MAX_RESULT_WINDOW |
Maximum search results | 20000000 |
No |
The service automatically creates and manages the following indices:
syncdata- Synchronized data storagequerybuilder- Saved user querieselement- Element dataprocedure_element- Procedure-related elements
The search engine supports complex queries with:
=- Wildcard match==- Exact match>,>=,<,<=- Range comparisons!=- Not wildcard match!==- Not exact match
AND- All conditions must matchOR- Any condition can match- Nested conditions with unlimited depth
{
"queryBuilderParams": {
"condition": "AND",
"rules": [
{
"field": "title,description",
"operator": "=",
"value": "search term"
},
{
"field": "created_date",
"operator": ">=",
"value": "2023-01-01"
}
]
},
"limit": 50,
"offset": 0,
"index": "element"
}The API uses JWT (JSON Web Tokens) for authentication:
- Public Key: Configure your JWT public key in the
PUBLIC_PEMenvironment variable - Algorithm: RS256 (RSA with SHA-256)
- Header: Include token in
Authorization: Bearer <token>header - Scope: User-specific data is automatically filtered by username from token
/api/v1/health- No authentication required/api-docs/*- API documentation access
The included Dockerfile creates an optimized production image:
- Based on Node.js 14.20.0
- Exposes port 3025
- Includes all dependencies
# Build image
docker build -t ingenium-search-server .
# Run container
docker run -d \
--name search-server \
-p 3025:3025 \
--env-file .env \
ingenium-search-serverCheck the search_examples/ directory for various usage examples:
curl_examples.txt- cURL command examplesquery.py- Python search examplesindex_example.py- Index management examplesdate_example.py- Date-based query examples
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow existing code style and conventions
- Add tests for new functionality
- Update documentation as needed
- Ensure all tests pass before submitting
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
βββ src/
β βββ api/ # OpenAPI specification
β βββ config/ # Configuration files
β βββ controllers/ # Request handlers
β βββ middlewares/ # Authentication & utility middleware
β βββ routes/ # API route definitions
β βββ utils/ # Logging and utilities
βββ search_examples/ # Usage examples
βββ Dockerfile # Container configuration
βββ package.json # Node.js dependencies
- Elasticsearch Integration: Optimized for large-scale document search
- JWT Middleware: Efficient token validation
- Configurable Limits: Tunable search result windows and field limits
- Connection Pooling: Automatic Elasticsearch connection management