spring-projects/spring-ai · error · RuntimeException
Not supported expression type:
Error message
Not supported expression type:
What it means
MongoDBAtlasFilterExpressionConverter.getOperationSymbol maps Spring AI Filter.Op values to MongoDB Atlas comparison operators ($lt, $gt, $in, etc.) and throws a RuntimeException("Not supported expression type:") in the default branch when it encounters an operator it cannot translate to an Atlas Search filter clause.
Source
Thrown at vector-stores/spring-ai-mongodb-atlas-store/src/main/java/org/springframework/ai/vectorstore/mongodb/atlas/MongoDBAtlasFilterExpressionConverter.java:81
context.append(getOperationSymbol(expression));
context.append(":");
this.convertOperand(expression.right(), context);
context.append("}}");
}
private String getOperationSymbol(Filter.Expression exp) {
return switch (exp.type()) {
case AND -> "$and";
case OR -> "$or";
case EQ -> "$eq";
case NE -> "$ne";
case LT -> "$lt";
case LTE -> "$lte";
case GT -> "$gt";
case GTE -> "$gte";
case IN -> "$in";
case NIN -> "$nin";
default -> throw new RuntimeException("Not supported expression type:" + exp.type());
};
}
@Override
protected void doKey(Filter.Key filterKey, StringBuilder context) {
var identifier = filterKey.key();
emitJsonValue("metadata." + identifier, context);
}
/**
* Serialize values using JSON serialization for MongoDB Atlas filter expressions.
* Delegates to {@link #emitJsonValue(Object, StringBuilder)} for Jackson-based JSON
* serialization.
* @param value the value to serialize
* @param context the context to append the JSON representation to
*/
@Override
protected void doSingleValue(Object value, StringBuilder context) {View on GitHub (pinned to 98a7beda4f)
Solutions
- Rewrite the filter using only supported operators: EQ, NE, GT, GTE, LT, LTE, IN, NIN.
- Replace LIKE/CONTAINS expressions with EQ against an exact value or precompute the match in metadata.
- Upgrade spring-ai-mongodb-atlas-store to the latest version for broader operator support.
- Implement a custom FilterExpressionConverter extending the Atlas converter to handle the missing op.
- Split complex filters into supported compound expressions (AND/OR of supported ops).
Example fix
// before
new FilterExpressionBuilder().like("genre", "doc").build();
// after
new FilterExpressionBuilder().eq("genre", "documentary").build(); // use supported EQ instead of LIKE Defensive patterns
Strategy: validation
Validate before calling
// validate filter ops before passing to Atlas search
static boolean isSupportedOp(Filter.Expression exp) {
return switch (exp.type()) {
case EQ, NE, GT, GTE, LT, LTE, IN, NIN, AND, OR -> true;
default -> false; // LIKE, CONTAINS etc. will throw in the Atlas converter
};
} Type guard
boolean isSupportedFilter(Expression filter) {
if (filter instanceof Filter.Expression exp) {
return isSupportedOp(exp);
}
return filter instanceof Filter.Group g && g.expressions().stream().allMatch(MyGuards::isSupportedFilter);
} Try / catch
try {
vectorStore.similaritySearch(SearchRequest.builder().query(q).filterExpression(expr).build());
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Not supported expression type")) {
throw new IllegalArgumentException("Rewrite filter with supported ops: EQ/NE/GT/GTE/LT/LTE/IN/NIN", e);
}
throw e;
} Prevention
- Only use EQ, NE, GT, GTE, LT, LTE, IN, NIN and AND/OR combinators in Atlas filter expressions.
- Avoid LIKE/CONTAINS ops which the Atlas converter cannot translate.
- Keep spring-ai core and the Atlas store module versions aligned.
- Unit-test filter expressions against the converter before deploying.
When it happens
Trigger: Passing a Filter.Expression whose Op is not EQ/NE/GT/GTE/LT/LTE/IN/NIN (e.g. LIKE, CONTAINS, or nested unsupported combinators) into a SearchRequest filter expression used with MongoDBAtlasVectorStore.
Common situations: Building a filter with string matching ops (LIKE/CONTAINS) which Atlas vector search filters do not support this way; using a newer Filter.Op added to Spring AI but not handled by this converter version; version drift between spring-ai-core and the Atlas store module.
Related errors
- Failed to delete documents by filter
- Not supported expression type:
- Unsupported operator:
- Unsupported operand type:
- Expression of type %s requires a left operand
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/f698c476b67bf720.
Report an issue: GitHub.