Skip to content

feat: migrate registry to OpenSearch 2.19.5 from Elasticsearch 7.10.1#361

Open
chethann007 wants to merge 6 commits into
Sunbird-RC:0.0.13.1from
chethann007:db-migration/es-to-opensearch
Open

feat: migrate registry to OpenSearch 2.19.5 from Elasticsearch 7.10.1#361
chethann007 wants to merge 6 commits into
Sunbird-RC:0.0.13.1from
chethann007:db-migration/es-to-opensearch

Conversation

@chethann007
Copy link
Copy Markdown

Description

Migrates registry and elastic-search modules from Elasticsearch 7.10.1 to OpenSearch 2.19.5. Updates Java dependencies, Docker base images, and API imports to ensure compatibility with OpenSearch 2.x architecture.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactor / Technical Debt
  • Test case addition/update

Microservice(s) Affected

  • registry (core)
  • elastic-search (core)

Changes

Dependencies (4cb5f7c3):

  • Replace elasticsearch-rest-high-level-client 7.10.1 with opensearch-rest-high-level-client 2.19.5
  • Pin Jackson (core, databind, annotations) to 2.18.2 (StreamWriteConstraints required by OpenSearch 2.x, added in Jackson 2.16)
  • Add zstd-jni 1.5.5-5 for compression support (CompressorRegistry requirement)
  • Pin httpcomponents versions: httpclient 4.5.14, httpcore 4.4.16, httpasyncclient 4.1.5, httpcore-nio 4.4.16
  • Add exclusions for httpclient-osgi and httpcore-osgi from all OpenSearch dependencies

Source migration:

  • Rewrite all org.elasticsearch.* imports to org.opensearch.* in ElasticServiceImpl.java and IElasticService.java
  • Update RestStatus import to org.opensearch.core.rest.RestStatus
  • Update CreateIndexRequest to use org.opensearch.client.indices package
  • Remove _doc type arguments from all operations — type system removed in OpenSearch 2.x
  • Remove ES_DOC_TYPE constant from Constants.java
  • Remove elasticService.setType() calls from entity configuration

Docker updates (1fc59ac3):

  • Root Dockerfile: Update base image frolvlad/alpine-java:jdk8-slimeclipse-temurin:11-jre-alpine
  • Update Spring Boot JAR launcher configuration to explode JAR and use JarLauncher for proper schema loading from mounted ConfigMap
  • Registry Dockerfile: Revert to openjdk:8-jdk-alpine (run integration tests with original base)

Docker Compose:

  • Update to opensearchproject/opensearch:2.19.5
  • Change env var ES_JAVA_OPTSOPENSEARCH_JAVA_OPTS
  • Add plugins.security.disabled=true for local dev

Test Artifacts (java/opensearch-api-test.md):

  • Added comprehensive curl-based API test guide for all 7 entity types
  • Covers CRUD operations, search filters, direct OpenSearch health checks
  • Includes test flow demonstrating full integration

How Has This Been Tested?

  • Local Docker Compose startup (OpenSearch cluster)
  • Entity CRUD operations via Keycloak-authenticated API endpoints
  • Search operations with filters
  • Schema loading from mounted ConfigMap volumes
  • Direct OpenSearch health checks and index queries
  • Verified pre-existing errors match production behavior (not migration-related)

Checklist

  • Self-review done
  • No new warnings introduced
  • Jackson version mismatch resolved (2.18.2 for StreamWriteConstraints)
  • Zstd compression dependency pinned
  • Httpcomponents versions pinned to match OpenSearch 2.x
  • Docker images verified for schema loading
  • API test guide provided for manual verification

Notes

  • Elasticsearch 7.10.1 → OpenSearch 2.19.5 is drop-in compatible at API level
  • StreamWriteConstraints missing in Jackson < 2.16; Spring Boot 2.3.x ships 2.11.4 (requires explicit pin)
  • ZstdCompressor in opensearch-compress requires zstd-jni 1.5.5-5 (transitive version 1.4.4-7 incompatible)
  • HTTP component conflicts resolved via explicit dependency pinning (httpclient-osgi/httpcore-osgi exclusions)
  • Registry Dockerfile remains openjdk:8 for production compatibility; root Dockerfile upgraded to eclipse-temurin:11 for schema resolution

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the registry’s search integration from Elasticsearch 7.10.1 to OpenSearch 2.19.5 by updating Java client dependencies/imports, removing deprecated document-type usage, and aligning local Docker tooling to run OpenSearch 2.x.

Changes:

  • Updated elastic-search module to use OpenSearch 2.19.5 clients/APIs and removed Elasticsearch document type usage.
  • Updated registry configuration/constants to stop passing _doc type.
  • Updated Docker/Docker Compose artifacts to run OpenSearch 2.19.5 and adjust Java runtime base image(s).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
java/registry/src/main/java/dev/sunbirdrc/registry/config/GenericConfiguration.java Removes setType(_doc) usage when wiring the elastic service bean.
java/registry/pom.xml Adds/pins dependencies (httpcomponents/Jackson) and excludes OSGi httpcomponents bundles from the Spring Boot fat jar.
java/registry/docker-compose.yml Switches local compose from Elasticsearch 7.10.1 to OpenSearch 2.19.5 and updates env vars accordingly.
java/middleware-commons/src/main/java/dev/sunbirdrc/registry/middleware/util/Constants.java Removes ES_DOC_TYPE constant now that types are removed.
java/elastic-search/src/main/java/dev/sunbirdrc/elastic/IElasticService.java Updates RestStatus import to OpenSearch.
java/elastic-search/src/main/java/dev/sunbirdrc/elastic/ElasticServiceImpl.java Migrates client API usage to OpenSearch and removes document type handling.
java/elastic-search/pom.xml Replaces Elasticsearch dependencies with OpenSearch 2.19.5 and pins related dependency versions; sets compiler target to Java 11.
java/Dockerfile Updates Java base image to Java 11 JRE (Alpine).
Comments suppressed due to low confidence (3)

java/elastic-search/src/main/java/dev/sunbirdrc/elastic/ElasticServiceImpl.java:189

  • addEntity() can throw a NullPointerException when the index request fails: IOException is caught, but response remains null and response.status() is still returned. Return a safe RestStatus (e.g., INTERNAL_SERVER_ERROR) or rethrow so callers can handle the failure explicitly.
    public RestStatus addEntity(String index, String entityId, JsonNode inputEntity) {
        logger.debug("addEntity starts with index {} and entityId {}", index, entityId);
        IndexResponse response = null;
        try {
            Map<String, Object> inputMap = JSONUtil.convertJsonNodeToMap(inputEntity);
            response = getClient(index).index(new IndexRequest(index).id(entityId).source(inputMap), RequestOptions.DEFAULT);
        } catch (IOException e) {
            logger.error("Exception in adding record to ElasticSearch", e);
        }
        return response.status();
    }

java/elastic-search/src/main/java/dev/sunbirdrc/elastic/ElasticServiceImpl.java:231

  • updateEntity() can throw a NullPointerException when the update request fails: IOException is caught, but response remains null and response.status() is still returned. Return a safe RestStatus (e.g., INTERNAL_SERVER_ERROR) or propagate the exception so failures don’t become NPEs.
    public RestStatus updateEntity(String index, String osid, JsonNode inputEntity) {
        logger.debug("updateEntity starts with index {} and entityId {}", index, osid);
        UpdateResponse response = null;
        try {
            Map<String, Object> inputMap = JSONUtil.convertJsonNodeToMap(inputEntity);
            logger.debug("updateEntity inputMap {}", inputMap);
            logger.debug("updateEntity inputEntity {}", inputEntity);
            response = getClient(index.toLowerCase()).update(new UpdateRequest(index.toLowerCase(), osid).doc(inputMap), RequestOptions.DEFAULT);
        } catch (IOException e) {
            logger.error("Exception in updating a record to ElasticSearch", e);
        }
        return response.status();
    }

java/elastic-search/src/main/java/dev/sunbirdrc/elastic/ElasticServiceImpl.java:252

  • deleteEntity() uses NullPointerException for control flow (when readEntity returns null) and also maps IOException to NOT_FOUND. This can hide real failures (e.g., OpenSearch unavailable) as 404s. Prefer an explicit null/exists check for the read result, and handle IOException separately (e.g., return an error status).
    public RestStatus deleteEntity(String index, String osid) {
        UpdateResponse response = null;
        try {
            String indexL = index.toLowerCase();
            Map<String, Object> readMap = readEntity(indexL, osid);
           // Map<String, Object> entityMap = (Map<String, Object>) readMap.get(index);
            readMap.put(Constants.STATUS_KEYWORD, Constants.STATUS_INACTIVE);
            response = getClient(indexL).update(new UpdateRequest(indexL, osid).doc(readMap), RequestOptions.DEFAULT);
        } catch (NullPointerException | IOException e) {
            logger.error("exception in deleteEntity {}", e);
            return RestStatus.NOT_FOUND;
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread java/registry/pom.xml
Comment thread java/registry/docker-compose.yml
Comment thread java/elastic-search/pom.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants