OrchardCMS/OrchardCore · error · ArgumentException
Invalid query
Error message
Invalid query
What it means
This is the fall-through case of MatchQueryProvider.CreateQuery: the field's JSON value is not one of the supported shapes (string or the recognized object/array forms), so the provider cannot build a match query and throws a generic ArgumentException('Invalid query').
Solutions
- Provide the search text as a JSON string: {"title": "quick"}.
- If using the object form, ensure it matches the provider's expected keys (e.g. "value", "minimum_should_match").
- Coerce non-string scalars to strings client-side before building the query.
Example fix
// before
{"published": true}
// after
{"published": "true"} Defensive patterns
Strategy: validation
Validate before calling
var k = query.Value.ValueKind;
if (k is not (JsonValueKind.String or JsonValueKind.Object))
throw new ArgumentException("match query value must be a string or a supported object"); Type guard
static bool IsMatchShape(JsonElement el) =>
el.ValueKind == JsonValueKind.String || el.ValueKind == JsonValueKind.Object; Try / catch
try { var query = provider.CreateQuery(context, queryJson); }
catch (ArgumentException ex) when (ex.Message == "Invalid query")
{ return BadRequest("Unsupported match query value shape; expected a string or object."); } Prevention
- Quote all scalars as strings in match query JSON.
- Never serialize null/unbound template variables into query values.
- Keep a schema of allowed match-query shapes and validate against it.
When it happens
Trigger: Calling CreateQuery with a match query whose value is an unsupported JSON kind — e.g. a boolean, number, or null like {"title": true} or {"title": null} instead of a string or the supported object form.
Common situations: Unquoted booleans/numbers in hand-written query JSON; null values from unbound template variables; client serializers emitting typed values instead of strings.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Invalid term in terms query
- Invalid terms query
- Invalid wildcard query
- Invalid fuzzy query
- Prefix query misses prefix value
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/2d828886ddb16a46.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/MatchQueryProvider.cs:65
if (terms.Count == 0)
{
if (obj.TryGetPropertyValue("zero_terms_query", out var zeroTermsQuery))
{
if (zeroTermsQuery.ToString() == "all")
{
return new MatchAllDocsQuery();
}
}
}
foreach (var term in terms)
{
boolQuery.Add(new TermQuery(new Term(first.Key, term)), occur);
}
return boolQuery;
default: throw new ArgumentException("Invalid query");
}
}
}
View on GitHub (pinned to 4306c0717f)