OrchardCMS/OrchardCore · error · ArgumentException
Invalid regexp query
Error message
Invalid regexp query
What it means
RegexpQueryProvider.CreateQuery dispatches on the JSON value kind; a regexp query must be a JSON object node. Any other value kind falls to the switch default and throws ArgumentException. This mirrors the other Lucene query providers' validation style.
Solutions
- Use the object form: {"field": {"type": "regexp", "value": "pattern"}}.
- Inspect the incoming JSON to find the malformed field node.
- Fix the query-producing code to wrap regexp specs in objects.
Example fix
// before
{"Title": "Orch.*"}
// after
{"Title": {"type": "regexp", "value": "Orch.*"}} Defensive patterns
Strategy: type-guard
Validate before calling
if (node?.GetValueKind() == JsonValueKind.Object) { /* safe to call */ } Type guard
static bool IsRegexpQueryObject(JsonNode node) => node is JsonObject o && o.TryGetPropertyValue("type", out var t) && t.GetValueKind() == JsonValueKind.String && t.GetValue<string>() == "regexp"; Try / catch
try { var q = provider.CreateQuery(node); } catch (ArgumentException ex) when (ex.Message == "Invalid regexp query") { // inspect and log the offending node } Prevention
- Represent regexp queries as objects with a "type": "regexp" discriminator.
- Test serialized queries round-trip through the provider.
- Centralize query JSON construction in one validated helper.
When it happens
Trigger: Passing {"field": "pattern"} or {"field": ["a", "b"]} where an object node with type 'regexp' is required.
Common situations: Query builders emitting plain values instead of the discriminated object; copy-paste between term and regexp syntax; corrupted saved queries.
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 prefix query
- Invalid range query
- Invalid term query
- Missing value in regexp query
- Invalid fuzzy query
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/c4f191cf2163e905.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/RegexpQueryProvider.cs:42
case JsonValueKind.Object:
var obj = first.Value.AsObject();
if (!obj.TryGetPropertyValue("value", out var value))
{
throw new ArgumentException("Missing value in regexp query");
}
// TODO: Support flags
var regexpQuery = new RegexpQuery(new Term(first.Key, value.Value<string>()));
if (obj.TryGetPropertyValue("boost", out var boost))
{
regexpQuery.Boost = boost.Value<float>();
}
return regexpQuery;
default: throw new ArgumentException("Invalid regexp query");
}
}
}
View on GitHub (pinned to 4306c0717f)