{"record":{"id":"fac7ab5f994748dc","repo":"OrchardCMS/OrchardCore","slug":"query-dsl-requires-a-query-property","errorCode":null,"errorMessage":"Query DSL requires a [query] property","messagePattern":"Query DSL requires a \\[query\\] property","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Lucene.Core/LuceneQueryService.cs","lineNumber":21,"sourceCode":"using Lucene.Net.Analysis;\nusing Lucene.Net.Analysis.TokenAttributes;\nusing Lucene.Net.Search;\n\nnamespace OrchardCore.Lucene;\n\npublic class LuceneQueryService : ILuceneQueryService\n{\n    private readonly IEnumerable<ILuceneQueryProvider> _queryProviders;\n\n    public LuceneQueryService(IEnumerable<ILuceneQueryProvider> queryProviders)\n    {\n        _queryProviders = queryProviders;\n    }\n\n    public Task<LuceneTopDocs> SearchAsync(LuceneQueryContext context, JsonObject queryObj)\n    {\n        var queryProp = queryObj[\"query\"].AsObject()\n            ?? throw new ArgumentException(\"Query DSL requires a [query] property\");\n\n        var query = CreateQueryFragment(context, queryProp);\n\n        var sortProperty = queryObj[\"sort\"];\n        var fromProperty = queryObj[\"from\"];\n        var sizeProperty = queryObj[\"size\"];\n\n        var size = sizeProperty.ValueOrDefault(10);\n        var from = fromProperty.ValueOrDefault(0);\n\n        string sortField = null;\n        string sortOrder = null;\n\n        var sortFields = new List<SortField>();\n\n        if (sortProperty is not null)\n        {\n            string sortType;","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/LuceneQueryService.cs#L3-L39","documentation":"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.","triggerScenarios":"Posting/executing a Lucene query JSON like {\"from\":0,\"size\":10} without a \"query\" property.","commonSituations":"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.","solutions":["Add a top-level \"query\" object to the JSON, e.g. {\"query\":{\"match_all\":{}}}.","If you truly want everything, use the match_all query provider instead of omitting \"query\".","Validate the JSON payload shape before sending it to the Lucene query service."],"exampleFix":"// before\n{\"from\":0,\"size\":10}\n// after\n{\"query\":{\"match_all\":{}},\"from\":0,\"size\":10}","handlingStrategy":"validation","validationCode":"if (queryJson is not JsonObject root || root[\"query\"] is not JsonObject)\n    throw new ArgumentException(\"Lucene query JSON must contain a top-level 'query' object.\");","typeGuard":"static bool HasQueryNode(JsonNode? node) => node is JsonObject o && o[\"query\"] is JsonObject;","tryCatchPattern":"try { return await luceneQueryService.SearchAsync(context, queryObj); }\ncatch (ArgumentException) { queryObj[\"query\"] = new JsonObject(); /* match_all */ ... }","preventionTips":["Always include a 'query' property, using {\"match_all\":{}} when everything should match.","Validate query JSON against the DSL schema before submitting saved queries."],"tags":["lucene","query-dsl","json"],"backgroundTag":"missing-required-argument","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}