Skip to content

ArianKheir/Multilingual-ElasticSearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multilingual Elasticsearch Search

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.

Table of Contents


Features

  • 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.

Architecture

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
Loading

Requirements

  • Java 17+
  • Maven 3.6+
  • Docker & Docker Compose (for containerized setup)

Getting Started

Running with Docker

  1. Clone the repository:

    git clone https://github.com/ArianKheir/Multilingual-ElasticSearch.git
    cd Multilingual-ElasticSearch
  2. Start the services:

    docker compose up --build

    This will start:

    • Elasticsearch (secured, port 9200)
    • Spring Boot API (port 8080)
  3. Access the API:

    • API base URL: http://localhost:8080/api/documents
    • Elasticsearch: http://localhost:9200 (user: elastic, password: see docker-compose.yaml)

Manual Setup

  1. Start Elasticsearch:

    • Install and run Elasticsearch 9.0.3 locally, or use Docker as above.
  2. Configure environment variables:

    • Set SPRING_ELASTICSEARCH_URIS, SPRING_ELASTICSEARCH_USERNAME, and SPRING_ELASTICSEARCH_PASSWORD as needed.
  3. Build and run the Spring Boot app:

    cd multilingual-search
    mvn clean package
    java -jar target/*.jar

API Documentation

Insert Document

  • 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 Conflict if the identifier already exists.

Search Documents

  • 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
    ]

Data Model

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

Configuration

  • Elasticsearch index: multilingual_documents
  • Index mapping: Ensures bodyAll is mapped as text for full-text search.
  • Environment variables:
    • SPRING_ELASTICSEARCH_URIS
    • SPRING_ELASTICSEARCH_USERNAME
    • SPRING_ELASTICSEARCH_PASSWORD

See docker-compose.yaml for example values.


Testing

  • Unit and integration tests are provided using JUnit and Mockito.
  • To run tests:
    cd multilingual-search
    mvn test

Troubleshooting

  • Elasticsearch connection errors: Ensure the service is running and credentials match.
  • Port conflicts: Change the exposed ports in docker-compose.yaml if needed.
  • Duplicate document error: Identifiers must be unique.

License

This project is licensed under the MIT License.


Author

Arian Kheirandish


Contributions are welcome! For issues or feature requests, please open an issue or submit a pull request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published