OrchardCMS/OrchardCore · error · ArgumentException
Invalid wildcard query
Error message
Invalid wildcard query
What it means
This is the fall-through case of MatchPhraseQueryProvider.CreateQuery. The default branch throws an ArgumentException whose message misleadingly says 'Invalid wildcard query' (a copy-paste from the wildcard provider), but it fires for match_phrase queries whose JSON value is neither a string nor the supported object form.
Solutions
- Provide the phrase as a JSON string: {"title": "quick brown fox"}.
- Or use the object form: {"title": {"value": "quick brown fox", "slop": 1}}.
- Ignore the 'wildcard' wording in the message; fix the match_phrase value shape instead.
Example fix
// before
{"title": ["quick brown fox"]}
// after
{"title": "quick brown fox"} 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_phrase query value must be a string or an object with 'value'"); Type guard
static bool IsMatchPhraseShape(JsonElement el) =>
el.ValueKind == JsonValueKind.String ||
(el.ValueKind == JsonValueKind.Object && el.TryGetProperty("value", out var v) && v.ValueKind == JsonValueKind.String); Try / catch
try { var query = provider.CreateQuery(context, queryJson); }
catch (ArgumentException ex) { return BadRequest($"Invalid match_phrase query: {ex.Message}"); } Prevention
- Note the misleading 'wildcard' message text — it still means a malformed match_phrase value.
- Pass phrases as strings; use object form only for slop/analyzer options.
- Sanitize client-supplied query JSON before provider dispatch.
When it happens
Trigger: Calling CreateQuery with a match_phrase query like {"title": ["quick fox"]} or {"title": 42} — any value type other than string or object with "value".
Common situations: Arrays of phrases supplied as a list; numeric or boolean values unquoted; confusion between the string and object query forms; the wrong error text also misleads debugging.
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
- Missing value in match phrase query
- Query DSL requires a [query] property
- Invalid property ' ' in boolean query
- Invalid value in boolean query
- Missing value in fuzzy query
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/bf0d287d9c28114a.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/MatchPhraseQueryProvider.cs:44
break;
case JsonValueKind.Object:
var obj = first.Value.AsObject();
if (!obj.TryGetPropertyValue("value", out value))
{
throw new ArgumentException("Missing value in match phrase query");
}
// TODO: read "analyzer" property
if (obj.TryGetPropertyValue("slop", out var slop))
{
phraseQuery.Slop = slop.Value<int>();
}
break;
default: throw new ArgumentException("Invalid wildcard query");
}
foreach (var term in LuceneQueryService.Tokenize(first.Key, value.Value<string>(), context.DefaultAnalyzer))
{
phraseQuery.Add(new Term(first.Key, term));
}
return phraseQuery;
}
}
View on GitHub (pinned to 4306c0717f)