OrchardCMS/OrchardCore · error · ArgumentException

Prefix query misses prefix value

Error message

Prefix query misses prefix value

What it means

PrefixFilterProvider.CreateFilteredQuery, when given a prefix filter with an object value, looks for a "prefix" property to build the Lucene PrefixQuery. If the object contains neither the handled property nor "prefix", it throws ArgumentException("Prefix query misses prefix value") because a prefix filter without a prefix string cannot be constructed.

Solutions

  1. Add the "prefix" property to the object: {"prefix": {"Title": {"prefix": "Orch", "boost": 2.0}}}.
  2. Check the property key spelling — it must be exactly "prefix", not "value" or "term".
  3. If a plain string value is accepted by this provider for simple cases, pass the prefix as a string instead of an object.
  4. Validate prefix filter objects for the "prefix" key before executing the query.

Example fix

// before
{"prefix": {"Title": {"boost": 2.0}}}
// after
{"prefix": {"Title": {"prefix": "Orch", "boost": 2.0}}}
Defensive patterns

Strategy: validation

Validate before calling

if (filter.TryGetPropertyValue(field, out var v) && v.ValueKind == JsonValueKind.Object &&
    !v.AsObject().TryGetPropertyValue("prefix", out _))
{
    throw new InvalidOperationException($"prefix filter for '{field}' requires a 'prefix' property.");
}

Type guard

static bool HasPrefixValue(JsonElement v) =>
    v.ValueKind != JsonValueKind.Object ||
    v.AsObject().TryGetPropertyValue("prefix", out _);

Try / catch

try
{
    var query = provider.CreateFilteredQuery(context);
}
catch (ArgumentException ex) when (ex.Message.Contains("misses prefix value"))
{
    _logger.LogError(ex, "prefix filter missing 'prefix' key: {Json}", filterJson);
    throw new QueryValidationException("prefix filter requires a 'prefix' property.", ex);
}

Prevention

When it happens

Trigger: Calling CreateFilteredQuery with {"prefix": {"Title": {"boost": 2.0}}} — an object that sets boost but omits the required "prefix" property; also an object containing only unrecognized keys.

Common situations: Hand-writing query JSON and confusing the property name (e.g. writing "value" or "term" instead of "prefix"); porting an Elasticsearch prefix clause (which uses "value") into Orchard's Lucene syntax; typo in the key in a saved recipe or query.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/PrefixFilterProvider.cs:46

        switch (first.Value.GetValueKind())
        {
            case JsonValueKind.String:
                prefixQuery = new PrefixQuery(new Term(first.Key, first.Value.ToString()));
                break;
            case JsonValueKind.Object:
                var obj = first.Value.AsObject();

                if (obj.TryGetPropertyValue("value", out var value))
                {
                    prefixQuery = new PrefixQuery(new Term(first.Key, value.Value<string>()));
                }
                else if (obj.TryGetPropertyValue("prefix", out var prefix))
                {
                    prefixQuery = new PrefixQuery(new Term(first.Key, prefix.Value<string>()));
                }
                else
                {
                    throw new ArgumentException("Prefix query misses prefix value");
                }

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

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

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

        return new FilteredQuery(booleanQuery, queryFilter);
    }
}

View on GitHub (pinned to 4306c0717f)