OrchardCMS/OrchardCore · error · ArgumentException

Query DSL requires a [query] property

Error message

Query DSL requires a [query] property

What it means

LuceneQueryService.SearchAsync expects the JSON query DSL document to have a top-level "query" object property. When it is absent (or null), the AsObject() call fails or yields null and the method throws ArgumentException to signal a malformed query document.

Solutions

  1. Add a top-level "query" object to the JSON, e.g. {"query":{"match_all":{}}}.
  2. If you truly want everything, use the match_all query provider instead of omitting "query".
  3. Validate the JSON payload shape before sending it to the Lucene query service.

Example fix

// before
{"from":0,"size":10}
// after
{"query":{"match_all":{}},"from":0,"size":10}
Defensive patterns

Strategy: validation

Validate before calling

if (queryJson is not JsonObject root || root["query"] is not JsonObject)
    throw new ArgumentException("Lucene query JSON must contain a top-level 'query' object.");

Type guard

static bool HasQueryNode(JsonNode? node) => node is JsonObject o && o["query"] is JsonObject;

Try / catch

try { return await luceneQueryService.SearchAsync(context, queryObj); }
catch (ArgumentException) { queryObj["query"] = new JsonObject(); /* match_all */ ... }

Prevention

When it happens

Trigger: Posting/executing a Lucene query JSON like {"from":0,"size":10} without a "query" property.

Common situations: Hand-written query JSON, saved queries edited in the admin UI, or API clients that omit the query node when only sorting/paging was intended.

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/fac7ab5f994748dc. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.Lucene.Core/LuceneQueryService.cs:21

using Lucene.Net.Analysis;
using Lucene.Net.Analysis.TokenAttributes;
using Lucene.Net.Search;

namespace OrchardCore.Lucene;

public class LuceneQueryService : ILuceneQueryService
{
    private readonly IEnumerable<ILuceneQueryProvider> _queryProviders;

    public LuceneQueryService(IEnumerable<ILuceneQueryProvider> queryProviders)
    {
        _queryProviders = queryProviders;
    }

    public Task<LuceneTopDocs> SearchAsync(LuceneQueryContext context, JsonObject queryObj)
    {
        var queryProp = queryObj["query"].AsObject()
            ?? throw new ArgumentException("Query DSL requires a [query] property");

        var query = CreateQueryFragment(context, queryProp);

        var sortProperty = queryObj["sort"];
        var fromProperty = queryObj["from"];
        var sizeProperty = queryObj["size"];

        var size = sizeProperty.ValueOrDefault(10);
        var from = fromProperty.ValueOrDefault(0);

        string sortField = null;
        string sortOrder = null;

        var sortFields = new List<SortField>();

        if (sortProperty is not null)
        {
            string sortType;

View on GitHub (pinned to 4306c0717f)