elastic/elasticsearch · error · IllegalArgumentException
length parameter must be provided
Error message
length parameter must be provided
What it means
The truncate token filter requires a positive integer length. The constructor reads settings.getAsInt("length", -1) and rejects any value <= 0. Because the default is -1, simply omitting the key is sufficient to trip the check, as is explicitly passing 0 or a negative number.
Source
Thrown at modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/TruncateTokenFilterFactory.java:27
package org.elasticsearch.analysis.common;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.miscellaneous.TruncateTokenFilter;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;
public class TruncateTokenFilterFactory extends AbstractTokenFilterFactory {
private final int length;
TruncateTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
super(name);
this.length = settings.getAsInt("length", -1);
if (length <= 0) {
throw new IllegalArgumentException("length parameter must be provided");
}
}
@Override
public TokenStream create(TokenStream tokenStream) {
return new TruncateTokenFilter(tokenStream, length);
}
}
View on GitHub (pinned to db6a809a66)
Solutions
- Add "length": N with N >= 1 (it is the maximum token length in characters; tokens longer than N are truncated to N).
- Verify the key is spelled exactly 'length' and lives inside the filter object.
- If you want no truncation, remove the filter entirely instead of passing 0.
Example fix
// before
"filter": { "my_trunc": { "type": "truncate" } }
// after
"filter": { "my_trunc": { "type": "truncate", "length": 10 } } Defensive patterns
Strategy: validation
Validate before calling
// Require a positive length on every truncate filter
static String checkTruncate(Map<String,Object> filter) {
if ("truncate".equals(filter.get("type"))) {
Object len = filter.get("length");
if (!(len instanceof Number) || ((Number) len).intValue() <= 0)
return "truncate filter requires length > 0";
}
return null;
} Prevention
- Treat 'length' as required for any truncate filter in templates.
- Lint analyzer definitions in CI for missing/invalid length values.
When it happens
Trigger: Creating an analyzer whose filter is type 'truncate' without a 'length' key, or with length <= 0.
Common situations: Copying a truncate example that omitted length; mistyping the key as 'max' or 'size'; intending 'no truncation' and passing 0.
Related errors
- classname is a required setting for esplugin
- classname is a forbidden for stable esplugin
- invalid deploymentTarget '{}', expected one of {}
- Number of nodes should be >= 1 but was {} for {}
- Cannot shrink {} to have {} nodes as it already has {}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/2b06724b242bd342.
Report an issue: GitHub.