OrchardCMS/OrchardCore · error · ArgumentException

Invalid wildcard query

Error message

Invalid wildcard query

What it means

This is the fall-through case of WildcardFilterProvider.CreateFilteredQuery: the field's JSON value is neither a scalar string nor an object with a "value" property (e.g. an array, number, or boolean), so no wildcard query can be constructed and it throws.

Solutions

  1. Provide the pattern as a JSON string: {"title": "foo*"}.
  2. Or use the object form with "value": {"title": {"value": "foo*"}}.
  3. If multiple patterns are needed, build a bool filter with several wildcard filters instead of an array.

Example fix

// before
{"title": ["foo*", "bar*"]}
// after
{"title": {"value": "foo*"}}
Defensive patterns

Strategy: validation

Validate before calling

var k = filter.Value.ValueKind;
if (k is not (JsonValueKind.String or JsonValueKind.Object))
    throw new ArgumentException("wildcard filter value must be a string or an object with 'value'");

Type guard

static bool IsWildcardShape(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.CreateFilteredQuery(context, filter); }
catch (ArgumentException ex) { return BadRequest($"Invalid wildcard filter: {ex.Message}"); }

Prevention

When it happens

Trigger: Calling CreateFilteredQuery with a filter like {"title": ["a", "b"]} or {"title": 123} — any value type other than string or the supported object form.

Common situations: Reusing terms-query JSON for wildcard filters; numeric wildcard patterns unquoted; lists of patterns supplied as an array which the provider does not support.

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


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/87d2b8c6f43c9caf. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/WildcardFilterProvider.cs:49

                wildcardQuery = new WildcardQuery(new Term(first.Key, first.Value.ToString()));
                break;
            case JsonValueKind.Object:
                var obj = first.Value.AsObject();

                if (!obj.TryGetPropertyValue("value", out var value))
                {
                    throw new ArgumentException("Missing value in wildcard query");
                }

                wildcardQuery = new WildcardQuery(new Term(first.Key, value.Value<string>()));

                if (obj.TryGetPropertyValue("boost", out var boost))
                {
                    wildcardQuery.Boost = boost.Value<float>();
                }

                break;
            default: throw new ArgumentException("Invalid wildcard query");
        }

        booleanQuery.Add(wildcardQuery, Occur.MUST);
        var queryFilter = new QueryWrapperFilter(wildcardQuery);

        return new FilteredQuery(booleanQuery, queryFilter);
    }
}

View on GitHub (pinned to 4306c0717f)