{"record":{"id":"e597c0944b3270a8","repo":"OrchardCMS/OrchardCore","slug":"index-mappings-cannot-be-null","errorCode":null,"errorMessage":"Index mappings cannot be null.","messagePattern":"Index mappings cannot be null\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Elasticsearch.Core/Services/ElasticsearchIndexManager.cs","lineNumber":468,"sourceCode":"                    !s_tokenFilterGetter.TryGetValue(typeObject.ToString(), out var tokenFilterType))\n                {\n                    continue;\n                }\n\n                RemoveTypeNode(filter.Value);\n\n                var tokenFilter = filter.Value.ToObject(tokenFilterType) as ITokenFilter;\n\n                if (tokenFilter is not null)\n                {\n                    indexSettings.Analysis.TokenFilters.Add(filter.Key, tokenFilter);\n                }\n            }\n        }\n\n        if (metadata.IndexMappings is null)\n        {\n            throw new InvalidOperationException(\"Index mappings cannot be null.\");\n        }\n\n        var createIndexRequest = new CreateIndexRequest(indexProfile.IndexFullName)\n        {\n            Settings = indexSettings,\n            Mappings = metadata.IndexMappings.Mapping ?? new TypeMapping(),\n        };\n\n        // Custom metadata to store the last indexing task id.\n        createIndexRequest.Mappings.Meta ??= new FluentDictionary<string, object>();\n\n        createIndexRequest.Mappings.Meta[ElasticsearchConstants.LastTaskIdMetadataKey] = 0;\n\n        return createIndexRequest;\n    }\n\n    private static IAnalyzer GetAnalyzer(JsonObject analyzerProperties)\n    {","sourceCodeStart":450,"sourceCodeEnd":486,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Elasticsearch.Core/Services/ElasticsearchIndexManager.cs#L450-L486","documentation":"ElasticsearchIndexManager builds a CreateIndexRequest from an index profile's stored metadata. The metadata.IndexMappings value is mandatory — it defines the Elasticsearch mappings for the index. When it is null the manager cannot construct a valid create-index request and throws.","triggerScenarios":"Calling createIndexRequest/GetCreateIndexRequest for an Elasticsearch index profile whose IndexMappings was never persisted (e.g. the index handler never populated mappings, metadata was partially saved, or the index was created before the mappings step ran).","commonSituations":"Interrupted indexing that saved metadata without mappings; manually edited index metadata documents; upgrading indexes created by older module versions that lacked the IndexMappings field; custom Elasticsearch index handlers that do not call the mapping description.","solutions":["Re-create the index from the admin UI so metadata.IndexMappings is regenerated by the index handler","Ensure your IContentItemIndexHandler / mapping description actually populates IndexMappings before creating the index","Delete the stale index profile metadata and rebuild: Features > Elasticsearch > rebuild the index","Inspect the stored metadata document (ElasticsearchDocumentStorage) and fix/restore the IndexMappings value"],"exampleFix":"// before\nmetadata.IndexMappings = null; // handler never set mappings\n// after\nvar builder = new ContentItemIndexBuilder(typeOptions, _logger);\nawait DescribeMappingsAsync(builder); // ensures IndexMappings populated before CreateIndexAsync","handlingStrategy":"validation","validationCode":"var metadata = await _indexStore.SearchAsync<ElasticsearchIndexMetadata>(m => m.IndexName == indexProfile.IndexName);\nif (metadata?.IndexMappings is null) throw new InvalidOperationException($\"Index '{indexProfile.IndexName}' has no mappings; rebuild the index first\");","typeGuard":"bool HasMappings(ElasticsearchIndexMetadata m) => m?.IndexMappings?.Mapping != null;","tryCatchPattern":"try { await indexManager.CreateAsync(indexProfile); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Index mappings cannot be null\")) { // trigger full re-index await _indexingService.RebuildIndexAsync(indexProfile.IndexName); }","preventionTips":["Always build indexes through the admin UI/API so the handler populates mappings","Don't hand-edit Elasticsearch index metadata documents","After upgrades, rebuild legacy indexes that predate IndexMappings"],"tags":["elasticsearch","indexing","configuration","null"],"backgroundTag":"missing-required-config-field","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"}