spring-projects/spring-ai · error · RuntimeException

Not supported expression type:

Error message

Not supported expression type: 

What it means

OpenSearchAiSearchFilterExpressionConverter.getOperationSymbol throws a RuntimeException when the Filter.ExpressionType being converted has no OpenSearch query-operator mapping in its switch (default branch). The OpenSearch converter supports a different set of types than other stores, so valid expressions elsewhere can fail here.

Solutions

  1. Restrict filter expressions to types supported by the OpenSearch converter (AND, OR, EQ, NE, LT, LTE, GT, GTE, NIN, IN via range handling).
  2. Inspect the converter source for the exact supported set in your Spring AI version.
  3. Align Spring AI versions so Filter.ExpressionType and the converter match.
  4. Add the missing case to getOperationSymbol if the type should be supported.

Example fix

// before
Filter.not(Filter.in("status", List.of("x"))) // NOT may hit the default branch
// after
Filter.nin("status", List.of("x")); // directly supported as "NOT "
Defensive patterns

Strategy: validation

Validate before calling

static boolean openSearchSupported(Filter.Expression exp) {
    return switch (exp.type()) {
        case AND, OR, EQ, NE, LT, LTE, GT, GTE, IN, NIN -> true;
        default -> false;
    };
}

Try / catch

try {
    openSearchStore.similaritySearch(request);
} catch (RuntimeException e) {
    if (e.getMessage().startsWith("Not supported expression type")) {
        // rewrite or drop the filter, then post-filter in memory
    }
}

Prevention

When it happens

Trigger: Running Neo4jVectorStore-style similaritySearch filters against OpenSearchVectorStore with an ExpressionType not in the switch (e.g. IN is handled via doStartValueRange/doEndValueRange but certain types like NOT-in-some-combination hit default).

Common situations: Reusing filter expressions built for another vector store (PgVector, Neo4j) with OpenSearch; Spring AI version mismatch adding new ExpressionType values; programmatic filter building with unsupported nodes.

Related errors


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/98c072201c2601af. Report an issue: GitHub.

Appendix: source

Thrown at vector-stores/spring-ai-opensearch-store/src/main/java/org/springframework/ai/vectorstore/opensearch/OpenSearchAiSearchFilterExpressionConverter.java:85

	}

	@Override
	protected void doAddValueRangeSpitter(Filter.Value listValue, StringBuilder context) {
		context.append(" OR ");
	}

	private String getOperationSymbol(Expression exp) {
		return switch (exp.type()) {
			case AND -> " AND ";
			case OR -> " OR ";
			case EQ, IN -> "";
			case NE -> " NOT ";
			case LT -> "<";
			case LTE -> "<=";
			case GT -> ">";
			case GTE -> ">=";
			case NIN -> "NOT ";
			default -> throw new RuntimeException("Not supported expression type: " + exp.type());
		};
	}

	@Override
	public void doKey(Key key, StringBuilder context) {
		var fieldPath = withMetaPrefix(key.key().trim());
		emitLuceneString(fieldPath, context);
		context.append(':');
	}

	public String withMetaPrefix(String identifier) {
		return "metadata." + identifier;
	}

	@Override
	protected void doValue(Filter.Value filterValue, StringBuilder context) {
		if (filterValue.value() instanceof List list) {
			int c = 0;

View on GitHub (pinned to 98a7beda4f)