Skip to content

Support OpenSearch 2 and 3 with the Elasticsearch index backend - #4993

Merged
porunov merged 1 commit into
JanusGraph:masterfrom
porunov:opensearch-support
Sep 30, 2026
Merged

porunov merged 1 commit into
JanusGraph:masterfrom
porunov:opensearch-support

Conversation

@porunov

@porunov porunov commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #4887

JanusGraph's Elasticsearch index backend now supports OpenSearch 2 and 3. There's also a new option, index.[X].elasticsearch.major-version, which sets the version explicitly so that auto-detection isn't needed.

Problem

OpenSearch was forked from Elasticsearch 7.10 and provides the Elasticsearch 7 API. However, its root endpoint reports its own version ("distribution": "opensearch", "number": "2.19.6" / "3.9.0"). JanusGraph parses that number as an Elasticsearch major version, and fails with Unsupported Elasticsearch server major version.

  • OpenSearch 2 has only worked with compatibility.override_main_response_version: true, which makes it report 7.10.2.
  • OpenSearch 3 removed that setting; OpenSearch refuses to start with it (unknown setting [compatibility.override_main_response_version]). So JanusGraph couldn't use OpenSearch 3 at all.

Changes

  • Detection: a cluster whose root endpoint reports the distribution opensearch with a major version of 2 or 3 is treated as Elasticsearch 7 (ElasticMajorVersion.fromServerVersion), and an info message is logged.
    • Other OpenSearch versions are rejected like unsupported Elasticsearch versions: "Unsupported OpenSearch server major version", with a hint to set major-version. That covers a future OpenSearch 4, a malformed version, and OpenSearch 1, which reached its end of life in May 2025 and which nothing tests. Users of OpenSearch 1 can set major-version=7, and it then behaves like Elasticsearch 7 including mapping types.
    • ElasticsearchIndexTest passes on OpenSearch 3 with this alone.
    • The only ES 7 behavior that doesn't fit is mapping types. OpenSearch 2 removed them: include_type_name is an unrecognized parameter.
  • Mapping types: when JanusGraph detects OpenSearch, use-mapping-for-es7 is ignored with a warning, and requests are always typeless, because OpenSearch 2 removed mapping types.
    • ElasticSearchClient.usesMappingTypes() (a default method, overridden by the REST client) exposes the flag JanusGraph actually uses, so ElasticsearchConfigTest checks the effective behavior. Its mapping-type variant therefore now also runs against OpenSearch and proves the override.
    • Everything else about ES 7 applies: retry_on_conflict, the scroll-context setup, and geo_shape prefix trees, which OpenSearch 3 still supports (the prefix-tree tests pass). So mapping OpenSearch to ES 8 would have given up a feature it has.
  • index.[X].elasticsearch.major-version (6–9, MASKABLE, no default): the major version of the Elasticsearch API which the cluster provides, as the maintainers asked for. When set, JanusGraph doesn't request GET / for the version.
    • This covers OpenSearch deployments or ES-compatible services whose root endpoint is restricted or reports something unusable.
    • For OpenSearch it's 7. With an explicit version (or override_main_response_version) JanusGraph can't tell that it's OpenSearch, so the docs and the option descriptions say to keep use-mapping-for-es7 disabled in that case.
    • The detection fallback warning and the "Unsupported Elasticsearch server major version" error now point to the option.
    • RestClientSetup passes it to the REST client through a new constructor overload. The old constructor still asks the cluster, so existing callers are unchanged.
  • Test container: for an OpenSearch image, the test container disables the security plugin and the demo configuration. It also leaves out Elasticsearch's X-Pack and GeoIP-downloader settings, which OpenSearch refuses to start with.
    • Which distribution an image is comes from the new system property elasticsearch.docker.distribution (elasticsearch/opensearch), which the opensearch2/opensearch3 profiles set. Without it, the parsed image's repository name decides (opensearchproject/opensearch from any registry), so the documented -Delasticsearch.docker.image=opensearchproject/opensearch form keeps working; a differently named OpenSearch image needs the property.
    • The image is accepted as a substitute for Elastic's in Testcontainers' ElasticsearchContainer; its single-node settings and "started" log wait work unchanged.
    • For OpenSearch, the tests' getEsMajorVersion() is 7.
  • CI: new profiles opensearch2 (2.19.6) and opensearch3 (3.9.0), each run on Java 11 and Java 25, like the ES lanes.
  • Docs:
    • a new OpenSearch section in elasticsearch.md: detection, mapping types, the override setting, major-version, and security-plugin configuration;
    • setup-max-open-scroll-contexts=false for users who may not update cluster settings, and for Amazon OpenSearch Service. AWS doesn't allow changing search.max_open_scroll_context, and otherwise graph open fails;
    • Amazon OpenSearch Service with IAM needs signed requests, i.e. a custom authenticator;
    • Amazon OpenSearch Serverless isn't supported: it has neither the scroll API nor stored scripts;
    • OpenSearch mentioned in the index-backend overview;
    • changelog upgrade notes;
    • OpenSearch in the compatibility matrix and tested versions;
    • the new profiles in TESTING.md;
    • janusgraph-cfg.md.

Tests

  • New unit tests:
    • ElasticMajorVersionTest: ES 6–9, OpenSearch 2 and 3, the 7.10.2 override, OpenSearch detection, and unsupported Elasticsearch and OpenSearch versions (1.x, 0.x, 4.x, 10.x, malformed, missing).
    • RestClientMajorVersionTest: a configured version sends no request, and a real OpenSearch 3.9.0 root response is detected as 7. With use-mapping-for-es7=true, an ES 7.17.8 response gets include_type_name, while OpenSearch doesn't. I checked that the OpenSearch case fails without the fix.
    • RestClientSetupTest: the option reaches the client, and the default is null.
  • ElasticsearchConfigTest: both variants run everywhere, with expectations based on the effective mapping-type use.
  • Locally, Java 11, against real containers. "The whole module" means everything except the CQL-based classes, whose Cassandra container doesn't work on my machine (the same on master). The one skip in each run is an @Disabled manual test.
    • OpenSearch 3.9.0: the whole module, 513 tests. The config, index and unit tests again after the review fixes: 351.
    • OpenSearch 2.19.6: the whole module, 513 tests. The config and index tests again after the review fixes: 293.
    • Elasticsearch 9.5.4: the whole module, 519 tests (more than on OpenSearch, because the mapping-type variants also count on ES).
    • Elasticsearch 7.17.8: the config and index tests, 293, including the mapping-type variants.
  • After rebasing onto master (with Upgrade to Solr 9 and Lucene 9 #4992) and the version check:
    • OpenSearch 3.9.0: the whole module, 520 tests, including the shared Float min/max assertions from Upgrade to Solr 9 and Lucene 9 #4992.
    • OpenSearch 2.19.6: the config tests (both variants), the version tests and the graph profiling test, 19 tests.
  • After the Copilot review fixes, the config tests (both variants), the version tests and the graph profiling test, 19 tests each, against:
    • Elasticsearch 9.5.4 with the default image (the container change leaves Elasticsearch alone);
    • OpenSearch 3.9.0 through -Popensearch3 (the explicit distribution property);
    • OpenSearch 2.19.6 through -Delasticsearch.docker.image=opensearchproject/opensearch without a profile (the repository-name fallback).
  • Build checks: mvn -fae validate (enforcer, RAT, Checkstyle) over the reactor.

Not included

  • Vector/k-NN search. As the issue says, OpenSearch's ML/k-NN differs from Elasticsearch's, so it's a separate feature (see Vector search support (Option A: Cassandra 5 SAI, Option B: ES/OS vector fields) #4839).
  • A built-in AWS SigV4 authenticator: it would add the AWS SDK. The existing custom authenticator hook can sign requests.
  • Existing issue, unchanged: if the REST client constructor throws (e.g. an unsupported version), RestClientSetup.connect doesn't close the low-level RestClient it built.

Note

Rebased onto master after #4992 (Solr 9) was merged.

Copilot's review comments are addressed: OpenSearch 1 is no longer accepted, so the code and the docs agree on "2 and 3"; the test container takes an explicit distribution property and otherwise compares the image's repository name instead of a substring; the mapping-types warning no longer says "OpenSearch 2" for OpenSearch 3; and the RestClientSetupTest stubs use nullable(ElasticMajorVersion.class).

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

OpenSearch detection currently accepts malformed and unsupported future major versions without validation.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Extends the Elasticsearch backend to support OpenSearch 2 and 3.

Changes:

  • Detects OpenSearch and applies Elasticsearch 7-compatible behavior without mapping types.
  • Adds an explicit Elasticsearch API major-version option.
  • Adds OpenSearch tests, CI lanes, container setup, and documentation.
File Description
TESTING.md Documents OpenSearch test profiles.
RestClientSetupTest.java Tests major-version configuration plumbing.
RestClientMajorVersionTest.java Tests detection and mapping-type behavior.
JanusGraphElasticsearchContainer.java Configures OpenSearch test containers.
ElasticsearchConfigTest.java Tests effective mapping behavior.
ElasticMajorVersionTest.java Covers version classification.
RestElasticSearchClient.java Detects OpenSearch and handles mapping types.
RestClientSetup.java Passes configured API versions to clients.
ElasticSearchIndex.java Defines the new option and exposes effective mappings.
ElasticSearchClient.java Adds mapping-type capability reporting.
ElasticMajorVersion.java Maps OpenSearch to the ES 7 API.
janusgraph-es/​pom.xml Adds OpenSearch test profiles.
docs/​index-backend/​index.md Mentions OpenSearch support.
docs/​index-backend/​elasticsearch.md Documents OpenSearch configuration.
docs/​configs/​janusgraph-cfg.md Documents the new option.
docs/​changelog.md Records compatibility and upgrade notes.
.github/​workflows/​ci-index-es.yml Adds OpenSearch CI jobs.
.github/​workflows/​ci-index-es-dummy.yml Mirrors the new CI matrix entries.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 3 Medium severity · 2 Low severity

Open (5)
Resolved since last review (1)

Comment thread docs/index-backend/elasticsearch.md Resolved
Comment thread docs/index-backend/elasticsearch.md Resolved
Fixes JanusGraph#4887

OpenSearch was forked from Elasticsearch 7.10 and provides its API, but
it reports its own version (2.x, 3.x) with the distribution
"opensearch". JanusGraph rejected these versions as unsupported
Elasticsearch versions. OpenSearch 2 only worked with
compatibility.override_main_response_version, and OpenSearch 3 removed
that setting.

* A cluster which reports the distribution opensearch with a major
  version of 2 or 3 is now treated as Elasticsearch 7. Other OpenSearch
  versions, including OpenSearch 1, which reached its end of life, are
  rejected like unsupported Elasticsearch versions.
* OpenSearch 2 removed mapping types, so when JanusGraph detects
  OpenSearch it ignores use-mapping-for-es7 with a warning, and requests
  are always typeless.
  ElasticSearchClient.usesMappingTypes() exposes the effective choice,
  which ElasticsearchConfigTest now checks against every cluster.
* The new option index.[X].elasticsearch.major-version sets the major
  version of the Elasticsearch API which the cluster provides (6 to 9).
  When it is set, JanusGraph doesn't ask the cluster for its version,
  which also lets ES compatible services work whose root endpoint
  doesn't report a usable version. The detection fallback and the
  unsupported version error point to it.
* The test container starts OpenSearch images with the security plugin
  disabled and without Elasticsearch's X-Pack and GeoIP settings, which
  OpenSearch refuses to start with. The property
  elasticsearch.docker.distribution, which the opensearch profiles set,
  says which distribution an image is; without it, the repository name
  of the image decides.
* New profiles opensearch2 (2.19.6) and opensearch3 (3.9.0) run the
  Elasticsearch tests against OpenSearch, and CI runs them on Java 11
  and 25.
* The docs describe OpenSearch support:
  * the security plugin
  * setup-max-open-scroll-contexts=false where the JanusGraph user may
    not update cluster settings, including Amazon OpenSearch Service
  * that Amazon OpenSearch Serverless (no scroll API, no stored scripts)
    isn't supported

Co-Authored-By: Oleksandr Porunov <alexandr.porunov@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Oleksandr Porunov <alexandr.porunov@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@porunov
porunov merged commit 5e2a8ee into JanusGraph:master Sep 30, 2026
214 of 216 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: OpenSearch v2 and v3 Support

2 participants