{"record":{"id":"1d188d3473ada6da","repo":"OrchardCMS/OrchardCore","slug":"invalid-query","errorCode":null,"errorMessage":"Invalid query","messagePattern":"Invalid query","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/MatchFilterProvider.cs","lineNumber":72,"sourceCode":"                {\n                    if (obj.TryGetPropertyValue(\"zero_terms_query\", out var zeroTermsQuery))\n                    {\n                        if (zeroTermsQuery.ToString() == \"all\")\n                        {\n                            var matchAllDocsQuery = new MatchAllDocsQuery();\n                            booleanQuery.Add(matchAllDocsQuery, Occur.MUST);\n                            break;\n                        }\n                    }\n                }\n\n                foreach (var term in terms)\n                {\n                    boolQuery.Add(new TermQuery(new Term(first.Key, term)), occur);\n                }\n\n                break;\n            default: throw new ArgumentException(\"Invalid query\");\n        }\n\n        booleanQuery.Add(boolQuery, Occur.MUST);\n        queryFilter = new QueryWrapperFilter(boolQuery);\n\n        return new FilteredQuery(booleanQuery, queryFilter);\n    }\n}\n","sourceCodeStart":54,"sourceCodeEnd":81,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/MatchFilterProvider.cs#L54-L81","documentation":"MatchFilterProvider.CreateFilteredQuery builds a Lucene boolean query from a JSON filter node. After handling Object and Array value kinds, the switch's default branch throws ArgumentException(\"Invalid query\") because the 'match' filter's value was neither a JSON object nor an array. The library only supports those two shapes for match filters.","triggerScenarios":"Passing a Lucene query filter where the 'match' property's value is a JSON string, number, true/false, or null — e.g. {\"match\": {\"Content\": \"hello\"}} — instead of the required object ({\"value\": ..., \"boost\": ...}) or array-of-terms form.","commonSituations":"Hand-writing Lucene query JSON in a Query module or recipe and using the simpler shape copied from the SQL/Elasticsearch query syntax; typing the value as a plain string because that reads naturally; a saved query breaking after validation rules were tightened in a newer Orchard Core version.","solutions":["Wrap the raw value in an object: use {\"match\": {\"Content\": {\"value\": \"hello\"}}} instead of {\"match\": {\"Content\": \"hello\"}}.","If matching multiple terms, pass an array of terms as the value instead of a scalar.","Inspect the query JSON in the admin Query editor and validate each filter's value kind before saving/running.","Log the offending filter JSON before calling CreateFilteredQuery to identify which filter node has the wrong shape."],"exampleFix":"// before\n{\"query\": {\"match\": {\"Content\": \"orchard\"}}}\n// after\n{\"query\": {\"match\": {\"Content\": {\"value\": \"orchard\", \"boost\": 1.0}}}}","handlingStrategy":"validation","validationCode":"if (filter.TryGetPropertyValue(field, out var v) &&\n    v.ValueKind is not (JsonValueKind.Object or JsonValueKind.Array))\n{\n    throw new InvalidOperationException(\n        $\"'match' filter for '{field}' must be an object or array, got {v.ValueKind}.\");\n}","typeGuard":"static bool IsValidMatchValue(JsonElement v) =>\n    v.ValueKind is JsonValueKind.Object or JsonValueKind.Array;","tryCatchPattern":"try\n{\n    var query = filterProvider.CreateFilteredQuery(context);\n}\ncatch (ArgumentException ex)\n{\n    _logger.LogError(ex, \"Invalid Lucene match filter: {Json}\", filterJson);\n    throw new QueryValidationException(\"Malformed match filter value; expected object or array.\", ex);\n}","preventionTips":["Always wrap match values in an object with a \"value\" property.","Validate filter JSON against the provider's expected shapes before saving queries.","Test custom query builders against each filter provider's accepted forms."],"tags":["lucene","query-filter","invalid-argument","json"],"backgroundTag":"invalid-argument-format","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"}