### Elasticsearch Version

8.5.3

### Installed Plugins

_No response_

### Java Version

_bundled_

### OS Version

n/a

### Problem Description

In version 7.x of ES you can set an "includes" settings in the "_source" mapping definition for a field within a nested field. 
If you are indexing a document that contains multiple nested fields where one of the fields **does not** contain a particular field, the document indexes without problems. 

However, doing the same in version 8.5.3  fails with a  "reason": "Unclosed object or array found".

### Steps to Reproduce

Create a mapping like this:

```
PUT testnested
{
  "mappings": {
    "_source": {
      "includes": [
        "doc.field2","doc.field1.field3"
      ]
    },
    "properties": {
      "doc": {
        "properties": {
          "field1": {
            "type": "nested",
            "properties": {
              "field1n1": {
                "type": "nested",
                "properties": {
                  "name": {
                    "type": "text"
                  }
                }
              },
              "field3": {
                "type": "text"
              }
            }
          },
          "field2": {
            "type": "object"
          }
            
          }
        }
      }
    }
  }
```

Then index a document like this:

```
POST testnested/_doc
{
  "doc": {
    "field1": [
      {
        "field1n1": [
          {
            "name": "peter"
          },
          {
            "name": "parker"
          }
        ],
        "field3": "test"
      },
      {
        
        "field4": "testfield3"
      }
    ]
  }
}
```

Receive error:

```
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse",
    "caused_by": {
      "type": "illegal_state_exception",
      "reason": "Failed to close the XContentBuilder",
      "caused_by": {
        "type": "i_o_exception",
        "reason": "Unclosed object or array found"
      }
    }
  },
  "status": 400
}
```

### Logs (if relevant)

_No response_
libs/x-content/src/test/java/org/elasticsearch/xcontent/support/filtering/AbstractXContentFilteringTestCase.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.xcontent.support.filtering;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.support.AbstractFilteringTestCase;
import org.elasticsearch.xcontent.XContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import java.util.stream.IntStream;
import static java.util.Collections.emptySet;
import static java.util.Collections.singleton;
import static java.util.stream.Collectors.joining;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
public abstract class AbstractXContentFilteringTestCase extends AbstractFilteringTestCase {