OrchardCMS/OrchardCore · error · ArgumentException
Invalid fuzzy query
Error message
Invalid fuzzy query
What it means
The fuzzy filter provider accepts the fuzzy value only as an object with a 'value' property (plus optional fuzziness/prefix_length/max_expansions/boost). Any other JSON kind (string, array, etc.) hits the default case and throws 'Invalid fuzzy query'.
Solutions
- Use the object form: {"fuzzy":{"field":{"value":"text","fuzziness":"AUTO"}}}.
- Never pass a raw string or array as the fuzzy value.
- Validate the fuzzy node's JSON kind is Object before sending.
Example fix
// before
{"fuzzy":{"title":"orchard"}}
// after
{"fuzzy":{"title":{"value":"orchard"}}} Defensive patterns
Strategy: type-guard
Validate before calling
if (fuzzyValue is not JsonObject)
throw new ArgumentException("Fuzzy value must be an object like {\"value\":\"text\"}."); Type guard
static bool IsFuzzyObject(JsonNode? n) => n is JsonObject o && o.ContainsKey("value"); Try / catch
try { return CreateFilteredQuery(...); }
catch (ArgumentException ex) when (ex.Message == "Invalid fuzzy query") { log.LogWarning("Bad fuzzy filter shape"); } Prevention
- Convert ES-style string shorthand to the object form when importing queries.
- Keep a small DSL schema validator for query JSON in your app.
When it happens
Trigger: Using {"fuzzy":{"field":"text"}} (string shorthand) or an array as the fuzzy value.
Common situations: Porting Elasticsearch queries that permit the shorthand string form for fuzzy.
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 fuzzy query
- Query DSL requires a [query] property
- Invalid property ' ' in boolean query
- Invalid value in boolean query
- Invalid geo point representation
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/1f1ee344bffcc739.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/FuzzyFilterProvider.cs:58
obj.TryGetPropertyValue("fuzziness", out var fuzziness);
obj.TryGetPropertyValue("prefix_length", out var prefixLength);
obj.TryGetPropertyValue("max_expansions", out var maxExpansions);
fuzzyQuery = new FuzzyQuery(
new Term(first.Key, value.Value<string>()),
fuzziness?.Value<int>() ?? LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE,
prefixLength?.Value<int>() ?? 0,
maxExpansions?.Value<int>() ?? 50,
true);
if (obj.TryGetPropertyValue("boost", out var boost))
{
fuzzyQuery.Boost = boost.Value<float>();
}
break;
default: throw new ArgumentException("Invalid fuzzy query");
}
booleanQuery.Add(fuzzyQuery, Occur.MUST);
var queryFilter = new QueryWrapperFilter(fuzzyQuery);
return new FilteredQuery(booleanQuery, queryFilter);
}
}
View on GitHub (pinned to 4306c0717f)