{"record":{"id":"46ef967083ef66d6","repo":"OrchardCMS/OrchardCore","slug":"the-terms-lookup-query-is-not-supported","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/Filters/TermsFilterProvider.cs","lineNumber":45,"sourceCode":"\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\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":27,"sourceCodeEnd":56,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/TermsFilterProvider.cs#L27-L56","documentation":"The terms query in this provider only supports arrays of string terms. When the field's JSON value is an object, this indicates the Elasticsearch 'terms lookup' syntax (fetching terms from another document), which Lucene's TermsFilterProvider does not implement, so it throws immediately.","triggerScenarios":"Calling CreateFilteredQuery with a filter like {\"field\": {\"index\": \"other\", \"id\": \"1\", \"path\": \"values\"}} — the Elasticsearch terms-lookup object form.","commonSituations":"Porting Elasticsearch queries that use terms lookup directly into Orchard Core Lucene filters without rewriting them into an explicit array of terms.","solutions":["Rewrite the terms lookup as an explicit array of string terms in the filter JSON.","Fetch the referenced document/terms in application code first, then pass the resulting array.","Catch ArgumentException and surface a message that terms lookup is unsupported in Lucene query filters."],"exampleFix":"// before\n{\"tags\": {\"index\": \"recipes\", \"id\": \"1\", \"path\": \"tag_ids\"}}\n// after\n{\"tags\": [\"tag1\", \"tag2\"]}","handlingStrategy":"validation","validationCode":"if (filter.Value.ValueKind == JsonValueKind.Object)\n    throw new ArgumentException(\"terms lookup is not supported; pass an explicit array of terms\");","typeGuard":"static bool IsSupportedTermsFilter(JsonElement el) => el.ValueKind == JsonValueKind.Array;","tryCatchPattern":"try { var query = provider.CreateFilteredQuery(context, filter); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"terms lookup\"))\n{ return BadRequest(\"Terms lookup queries are not supported by Lucene filters; use an explicit term array.\"); }","preventionTips":["Never copy Elasticsearch terms-lookup syntax into Orchard Lucene filters.","Resolve lookup documents in application code and inline the term array.","Document supported filter shapes for API consumers."],"tags":["lucene","unsupported-feature","elasticsearch-compat"],"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"}