{"record":{"id":"ff56d2acb20eceb8","repo":"OrchardCMS/OrchardCore","slug":"invalid-terms-query","errorCode":null,"errorMessage":"Invalid terms query","messagePattern":"Invalid terms query","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/TermsFilterProvider.cs","lineNumber":47,"sourceCode":"        {\n            case JsonValueKind.Array:\n\n                foreach (var item in first.Value.AsArray())\n                {\n                    if (item.GetValueKind() != JsonValueKind.String)\n                    {\n                        throw new ArgumentException($\"Invalid term in terms query\");\n                    }\n\n                    boolQuery.Add(new TermQuery(new Term(field, item.Value<string>())), Occur.SHOULD);\n                }\n\n                break;\n\n            case JsonValueKind.Object:\n                throw new ArgumentException(\"The terms lookup query is not supported\");\n\n            default: throw new ArgumentException(\"Invalid terms query\");\n        }\n\n        booleanQuery.Add(boolQuery, Occur.MUST);\n        var queryFilter = new QueryWrapperFilter(boolQuery);\n\n        return new FilteredQuery(booleanQuery, queryFilter);\n    }\n}\n","sourceCodeStart":29,"sourceCodeEnd":56,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/TermsFilterProvider.cs#L29-L56","documentation":"This is the fall-through case of TermsFilterProvider.CreateFilteredQuery: the field's JSON value is neither an array nor an object (e.g. a bare string, number, boolean, or null), which cannot be interpreted as a terms query, so an ArgumentException is thrown.","triggerScenarios":"Calling CreateFilteredQuery with a filter like {\"field\": \"value\"} or {\"field\": 42} where the value is not a JSON array (terms list) or object (unsupported lookup).","commonSituations":"Confusing the 'term' query form (single scalar) with 'terms' (array); code generators emitting scalars for single-element term lists; malformed filter JSON from client templates.","solutions":["Wrap the scalar in a JSON array: {\"field\": [\"value\"]}.","Use the term filter provider instead of the terms provider for single scalar values.","Validate the filter shape (value must be an array of strings) before calling CreateFilteredQuery."],"exampleFix":"// before\n{\"status\": \"published\"}\n// after\n{\"status\": [\"published\"]}","handlingStrategy":"validation","validationCode":"if (filter.Value.ValueKind is not (JsonValueKind.Array or JsonValueKind.Object))\n    throw new ArgumentException(\"terms filter value must be an array of strings\");","typeGuard":"static bool IsTermsShape(JsonElement el) => el.ValueKind == JsonValueKind.Array;\nstatic bool IsTermShape(JsonElement el) => el.ValueKind == JsonValueKind.String;","tryCatchPattern":"try { var query = provider.CreateFilteredQuery(context, filter); }\ncatch (ArgumentException ex) { return BadRequest($\"Invalid terms query shape: {ex.Message}\"); }","preventionTips":["Use 'term' providers for scalars and 'terms' providers for arrays — keep them distinct.","Validate the JSON shape before calling the provider.","Test single-element and multi-element terms arrays in unit tests."],"tags":["lucene","query-validation","json-shape"],"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"}