{"record":{"id":"df382320cf3527e4","repo":"OrchardCMS/OrchardCore","slug":"the-terms-lookup-query-is-not-supported-termsqueryprovider","errorCode":null,"errorMessage":"The terms lookup query is not supported","messagePattern":"The terms lookup query is not supported","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/TermsQueryProvider.cs","lineNumber":38,"sourceCode":"        var boolQuery = new BooleanQuery();\n\n        switch (first.Value.GetValueKind())\n        {\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            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        return boolQuery;\n    }\n}\n","sourceCodeStart":20,"sourceCodeEnd":46,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/TermsQueryProvider.cs#L20-L46","documentation":"Lucene's TermsQueryProvider builds a terms query from a JSON value. When the JSON value for the field is an object, the provider interprets it as an Elasticsearch-style terms-lookup query, which Lucene's TermsQuery cannot express, so it throws ArgumentException immediately.","triggerScenarios":"Calling CreateQuery with a terms query whose JSON value for the field is a JSON object (JsonValueKind.Object), e.g. {\"terms\": {\"myField\": {\"id\": \"doc1\", \"path\": \"some.path\"}}}.","commonSituations":"Porting Elasticsearch queries that use terms lookup (fetching terms from another document) directly into Orchard Core Lucene queries without rewriting them into an explicit list of values.","solutions":["Replace the object value with an explicit JSON array of term values, e.g. {\"myField\": [\"a\",\"b\"]}.","Fetch the terms yourself (query the source document first) and inline the values as an array.","If terms lookup is essential, use a query provider/store that supports it (e.g. Elasticsearch integration) instead of Lucene."],"exampleFix":"// before\n{\"query\": {\"terms\": {\"role\": {\"id\": \"user1\", \"path\": \"roles\"}}}}\n// after\n{\"query\": {\"terms\": {\"role\": [\"editor\", \"author\"]}}}","handlingStrategy":"validation","validationCode":"if (termsValue.ValueKind == JsonValueKind.Object)\n    throw new InvalidOperationException(\"Terms lookup (object value) is not supported by Lucene terms query; supply an array of values.\");","typeGuard":"static bool IsSupportedTermsValue(JsonElement el) => el.ValueKind == JsonValueKind.Array || el.ValueKind == JsonValueKind.String;","tryCatchPattern":"catch (ArgumentException ex) when (ex.Message.Contains(\"terms lookup\"))\n{\n    // rewrite query or surface 'unsupported query' to user\n}","preventionTips":["Never port Elasticsearch terms-lookup queries verbatim into Lucene query JSON.","Resolve referenced terms client-side and inline them as arrays.","Add a query-JSON pre-validator for Lucene query providers."],"tags":["lucene","query","unsupported-feature"],"backgroundTag":"unsupported-operation","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"}