### Elasticsearch Version

8.6.0

### Installed Plugins

_No response_

### Java Version

_bundled_

### OS Version

Ubuntu 22.04

### Problem Description

Indexing a large (larger than the Lucene 32k field limit) keyword field with `index: false` and `doc_values: false` produces HTTP 400 error during bulk operation, but I assume this is the case when indexing a single document.

We know this field can get big, really big and we would like to store it only, no indexing, aggregation, nothing, just store them in the `_source`. 
Last year we migrated our app to v8.1.x, worked without issues, but now going up to a more recent version breaks one of our integration tests. It also works with earlier Elasticsearch 7 versions.

It seems that there is an ordering issue in this method:
https://github.com/elastic/elasticsearch/blob/8.6/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java#L1009-L1036

The check for large field value happens before checking whether we need to index it to Lucene or not.

Related issue and PR:
https://github.com/elastic/elasticsearch/issues/80865
https://github.com/elastic/elasticsearch/pull/83738

### Steps to Reproduce

* Create an index with the following mapping:

```
{
  "document" : {
    "mappings" : {
      "properties" : {
        "result" : {
          "type" : "keyword",
          "index" : false,
          "doc_values" : false
        }
      }
    }
  }
}
```


* Index the following document:

```
{
  "result": "really_long_field_value" // really long larger than Lucene 32k limit
}
``` 

### Logs (if relevant)

In the logs, this is the row that contains the error but unfortunately, it is shadowed by a `toString` limit error that happened during the reporting of the original error:

```
{"@timestamp":"2023-01-18T13:32:59.391Z", "log.level":"DEBUG", "message":"[api-test.jobs-job][0] failed to execute bulk item (index) index {[api-test.jobs-job][f751de755246a6e49379673c986c5b71964ccef4], source[n/a, actual length: [86.7kb], max length: 2kb]}", "ecs.version": "1.2.0","service.name":"ES_ECS","event.dataset":"elasticsearch.server","process.thread.name":"elasticsearch[35fff08b2f23][write][T#2]","log.logger":"org.elasticsearch.action.bulk.TransportShardBulkAction","elasticsearch.cluster.uuid":"o2LFisQoSASEf6EW31G6Hw","elasticsearch.node.id":"o3uFD1twQlqxoMY7oNUk9w","elasticsearch.node.name":"35fff08b2f23","elasticsearch.cluster.name":"docker-cluster","error.type":"org.elasticsearch.index.mapper.MapperParsingException","error.message":"failed to parse field [result] of type [keyword] in document with id 'f751de755246a6e49379673c986c5b71964ccef4'. Preview of field's value: '{\"visitedComponents\":[\"codesystems/SNOMEDCT/concept/246246002\",\"codesystems/SNOMEDCT/concept/246487003\",\"codesystems/SNOME
```

The root cause can be seen at the end of the log entry:

```
Document contains at least one immense term in field=\"result\" (whose UTF8 encoding is longer than the max length 32766), all of which were skipped. Please correct the analyzer to not produce such terms. The prefix of the first immense term is: '[123, 34, 118, 105, 115, 105, 116, 101, 100, 67, 111, 109, 112, 111, 110, 101, 110, 116, 115, 34, 58, 91, 34, 99, 111, 100, 101, 115, 121, 115]...'\n\tat org.elasticsearch.server@8.6.0/org.elasticsearch.index.mapper.KeywordFieldMapper.indexValue(KeywordFieldMapper.java:960)\n\tat org.elasticsearch.server@8.6.0/org.elasticsearch.index.mapper.KeywordFieldMapper.parseCreateField(KeywordFieldMapper.java:912)\n\tat org.elasticsearch.server@8.6.0/org.elasticsearch.index.mapper.FieldMapper.parse(FieldMapper.java:155)\n\t... 22 more\n"}
```,
server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java
}
    public void testEnableNorms() throws IOException {
        DocumentMapper mapper = createDocumentMapper(
            fieldMapping(b -> b.field("type", "keyword").field("doc_values", false).field("norms", true))
        );
        ParsedDocument doc = mapper.parse(source(b -> b.field("field", "1234")));
        IndexableField[] fields = doc.rootDoc().getFields("field");
        assertEquals(1, fields.length);
        assertFalse(fields[0].fieldType().omitNorms());
        IndexableField[] fieldNamesFields = doc.rootDoc().getFields(FieldNamesFieldMapper.NAME);
        assertEquals(0, fieldNamesFields.length);
    }
    public void testDimension() throws IOException {
        
        MapperService mapperService = createMapperService(fieldMapping(b -> minimalMapping(b)));
        KeywordFieldMapper.KeywordFieldType ft = (KeywordFieldMapper.KeywordFieldType) mapperService.fieldType("field");
        assertFalse(ft.isDimension());
        assertDimension(true, KeywordFieldMapper.KeywordFieldType::isDimension);
        assertDimension(false, KeywordFieldMapper.KeywordFieldType::isDimension);
    }
    public void testDimensionAndIgnoreAbove() {
        Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
            minimalMapping(b);
            b.field("time_series_dimension", true).field("ignore_above", 2048);
        })));
        assertThat(
            e.getCause().getMessage(),
            containsString("Field [ignore_above] cannot be set in conjunction with field [time_series_dimension]")
        );
    }