OrchardCMS/OrchardCore · error · ArgumentException
Invalid query
Error message
Invalid query
What it means
MatchFilterProvider.CreateFilteredQuery builds a Lucene boolean query from a JSON filter node. After handling Object and Array value kinds, the switch's default branch throws ArgumentException("Invalid query") because the 'match' filter's value was neither a JSON object nor an array. The library only supports those two shapes for match filters.
Solutions
- Wrap the raw value in an object: use {"match": {"Content": {"value": "hello"}}} instead of {"match": {"Content": "hello"}}.
- If matching multiple terms, pass an array of terms as the value instead of a scalar.
- Inspect the query JSON in the admin Query editor and validate each filter's value kind before saving/running.
- Log the offending filter JSON before calling CreateFilteredQuery to identify which filter node has the wrong shape.
Example fix
// before
{"query": {"match": {"Content": "orchard"}}}
// after
{"query": {"match": {"Content": {"value": "orchard", "boost": 1.0}}}} Defensive patterns
Strategy: validation
Validate before calling
if (filter.TryGetPropertyValue(field, out var v) &&
v.ValueKind is not (JsonValueKind.Object or JsonValueKind.Array))
{
throw new InvalidOperationException(
$"'match' filter for '{field}' must be an object or array, got {v.ValueKind}.");
} Type guard
static bool IsValidMatchValue(JsonElement v) =>
v.ValueKind is JsonValueKind.Object or JsonValueKind.Array; Try / catch
try
{
var query = filterProvider.CreateFilteredQuery(context);
}
catch (ArgumentException ex)
{
_logger.LogError(ex, "Invalid Lucene match filter: {Json}", filterJson);
throw new QueryValidationException("Malformed match filter value; expected object or array.", ex);
} Prevention
- Always wrap match values in an object with a "value" property.
- Validate filter JSON against the provider's expected shapes before saving queries.
- Test custom query builders against each filter provider's accepted forms.
When it happens
Trigger: Passing a Lucene query filter where the 'match' property's value is a JSON string, number, true/false, or null — e.g. {"match": {"Content": "hello"}} — instead of the required object ({"value": ..., "boost": ...}) or array-of-terms form.
Common situations: Hand-writing Lucene query JSON in a Query module or recipe and using the simpler shape copied from the SQL/Elasticsearch query syntax; typing the value as a plain string because that reads naturally; a saved query breaking after validation rules were tightened in a newer Orchard Core version.
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 wildcard query
- Invalid prefix query
- Missing value in match phrase query
- Prefix query misses prefix value
- Invalid range query
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/1d188d3473ada6da.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/MatchFilterProvider.cs:72
{
if (obj.TryGetPropertyValue("zero_terms_query", out var zeroTermsQuery))
{
if (zeroTermsQuery.ToString() == "all")
{
var matchAllDocsQuery = new MatchAllDocsQuery();
booleanQuery.Add(matchAllDocsQuery, Occur.MUST);
break;
}
}
}
foreach (var term in terms)
{
boolQuery.Add(new TermQuery(new Term(first.Key, term)), occur);
}
break;
default: throw new ArgumentException("Invalid query");
}
booleanQuery.Add(boolQuery, Occur.MUST);
queryFilter = new QueryWrapperFilter(boolQuery);
return new FilteredQuery(booleanQuery, queryFilter);
}
}
View on GitHub (pinned to 4306c0717f)