elastic/elasticsearch · error · IllegalArgumentException

Cannot set Elasticsearch Distribution type to ${type}. Type

Error message

Cannot set Elasticsearch Distribution type to ${type}. Type unknown.

What it means

ElasticsearchDistribution.setType(String) only recognises the names of ARCHIVE and INTEG_TEST_ZIP because, per its javadoc, only public distribution types are supported here. Any other string (docker, rpm, deb, or a typo) is rejected. The typed overload setType(ElasticsearchDistributionType) must be used for the other types.

Source

Thrown at build-tools/src/main/java/org/elasticsearch/gradle/ElasticsearchDistribution.java:134

    public ElasticsearchDistributionType getType() {
        return type.get();
    }

    public void setType(ElasticsearchDistributionType type) {
        this.type.set(type);
    }

    /**
     * For simplicity only public distribution types are supported here
     * */
    public void setType(String type) {
        if (type.equals(ElasticsearchDistributionTypes.ARCHIVE.getName())) {
            this.type.set(ElasticsearchDistributionTypes.ARCHIVE);
        } else if (type.equals(ElasticsearchDistributionTypes.INTEG_TEST_ZIP.getName())) {
            this.type.set(ElasticsearchDistributionTypes.INTEG_TEST_ZIP);
        } else {
            throw new IllegalArgumentException("Cannot set Elasticsearch Distribution type to " + type + ". Type unknown.");
        }
    }

    public boolean getBundledJdk() {
        return bundledJdk.getOrElse(true);
    }

    public boolean isDocker() {
        return this.type.get().isDocker();
    }

    public void setBundledJdk(Boolean bundledJdk) {
        this.bundledJdk.set(bundledJdk);
    }

    public boolean getFailIfUnavailable() {
        return this.failIfUnavailable.get();
    }

View on GitHub (pinned to db6a809a66)

Solutions

  1. For docker/rpm/deb use the enum overload: distribution.setType(ElasticsearchDistributionTypes.DOCKER).
  2. For archive/integ_test_zip ensure the string exactly matches ElasticsearchDistributionTypes.<TYPE>.getName().
  3. Trim and verify the spelling against the enum constant.

Example fix

// before
distribution.setType('docker')
// after
import org.elasticsearch.gradle.distribution.ElasticsearchDistributionTypes
distribution.setType(ElasticsearchDistributionTypes.DOCKER)
Defensive patterns

Strategy: validation

Validate before calling

static ElasticsearchDistributionType resolveType(String name) {
    for (ElasticsearchDistributionType t : ElasticsearchDistributionTypes.values()) {
        if (t.getName().equals(name)) return t;
    }
    throw new IllegalArgumentException("Unknown distribution type name: " + name);
}
distribution.setType(resolveType(typeName));

Type guard

static boolean isKnownTypeName(String name) {
    return Arrays.stream(ElasticsearchDistributionTypes.values())
        .map(ElasticsearchDistributionType::getName).anyMatch(name::equals);
}

Prevention

When it happens

Trigger: A build script calls distribution.setType("docker") or setType("rpm") instead of the typed enum overload, or passes a misspelled name like "archive " (trailing space) or "integ-zip".

Common situations: A contributor assumes the string overload covers all distribution types; a copy-paste from older API docs; trailing whitespace from a generated script.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/1de12bd7e2ea84fd. Report an issue: GitHub.