We have a check that enforces the total number of fields needs to be below a certain (configurable) threshold in each index. 

Runtime fields currently do not contribute to the count. There have been misunderstandings around this, caused by runtime fields not having a corresponding lucene field. Object fields and alias fields don't have corresponding lucene fields either yet they count towards the total fields limit.

The original goal of the total fields limit is to prevent a mappings explosion caused by a bogus document being indexed, as it would cause fields being dynamically added to the index mappings, which hinders stability due to the cluster state size of mappings as well as memory footprint of mappings in data nodes.

Runtime fields contribute to cluster state size and memory footprint of mappings like any other field, and they can be created dynamically when [`dynamic` is set to `runtime`](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic.html#dynamic-parameters). Currently a bogus document can cause a mappings explosion when `dynamic` is set to `runtime` which is a bug. For this reason runtime fields should be counted towards the total fields count.
server/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */
package org.elasticsearch.index.mapper;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.mapper.MapperService.MergeReason;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import java.io.IOException;
import java.util.List;
import java.util.stream.StreamSupport;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
public class MapperServiceTests extends MapperServiceTestCase {