A Spring Boot REST API for storing and searching multilingual documents using Elasticsearch. This project enables efficient full-text search across multiple languages, making it ideal for applications requiring internationalization and multilingual content management.
- Features
- Architecture
- Requirements
- Getting Started
- API Documentation
- Data Model
- Configuration
- Testing
- Troubleshooting
- License
- Author
- Store documents with content in multiple languages.
- Full-text search across all languages in a single query.
- RESTful API for document management.
- Optimized Elasticsearch index and mapping.
- Dockerized for easy deployment.
- Secure Elasticsearch setup with authentication.
graph TD
Client["Client (e.g., Postman, Frontend App)"]
API["Spring Boot REST API"]
ES["Elasticsearch 9.0.3"]
Client -->|HTTP/JSON| API
API -->|Elasticsearch Java API| ES
- Java 17+
- Maven 3.6+
- Docker & Docker Compose (for containerized setup)
-
Clone the repository:
git clone https://github.com/ArianKheir/Multilingual-ElasticSearch.git cd Multilingual-ElasticSearch -
Start the services:
docker compose up --build
This will start:
- Elasticsearch (secured, port
9200) - Spring Boot API (port
8080)
- Elasticsearch (secured, port
-
Access the API:
- API base URL:
http://localhost:8080/api/documents - Elasticsearch:
http://localhost:9200(user:elastic, password: seedocker-compose.yaml)
- API base URL:
-
Start Elasticsearch:
- Install and run Elasticsearch 9.0.3 locally, or use Docker as above.
-
Configure environment variables:
- Set
SPRING_ELASTICSEARCH_URIS,SPRING_ELASTICSEARCH_USERNAME, andSPRING_ELASTICSEARCH_PASSWORDas needed.
- Set
-
Build and run the Spring Boot app:
cd multilingual-search mvn clean package java -jar target/*.jar
- Endpoint:
POST /api/documents - Description: Insert a new multilingual document.
- Request Body:
{ "identifier": "doc1", "body": { "en": "Hello", "fa": "سلام" } } - Response:
200 OK{ "identifier": "doc1", "body": { "en": "Hello", "fa": "سلام" }, "bodyAll": "Hello سلام" } - Errors:
409 Conflictif the identifier already exists.
- Endpoint:
GET /api/documents/search?text={query}&size={N} - Description: Search for documents containing the given text in any language.
- Parameters:
text(required): The search query.size(optional): Max number of results (default: 10).
- Response:
200 OK[ { "identifier": "doc1", "body": { "en": "Hello", "fa": "سلام" }, "bodyAll": "Hello سلام" } // ... more documents ]
A document is represented as:
| Field | Type | Description |
|---|---|---|
| identifier | string | Unique document ID |
| body | map[string]string | Language code to text (e.g., "en", "fa") |
| bodyAll | string | Concatenated text for optimized search |
- Elasticsearch index:
multilingual_documents - Index mapping: Ensures
bodyAllis mapped astextfor full-text search. - Environment variables:
SPRING_ELASTICSEARCH_URISSPRING_ELASTICSEARCH_USERNAMESPRING_ELASTICSEARCH_PASSWORD
See docker-compose.yaml for example values.
- Unit and integration tests are provided using JUnit and Mockito.
- To run tests:
cd multilingual-search mvn test
- Elasticsearch connection errors: Ensure the service is running and credentials match.
- Port conflicts: Change the exposed ports in
docker-compose.yamlif needed. - Duplicate document error: Identifiers must be unique.
This project is licensed under the MIT License.
Arian Kheirandish
Contributions are welcome! For issues or feature requests, please open an issue or submit a pull request.