### 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
public void testDotInIncludedFieldNamePatternUnconfigured() throws IOException {
        testFilter(
            builder -> builder.startObject().endObject(),
            builder -> builder.startObject().field("foo.bar", "test").endObject(),
            singleton(randomFrom("foo.*", "*.bar", "f*.bar", "foo.*ar", "*.*")),
            emptySet(),
            false
        );
    }
    public void testDotInIncludedFieldNamePatternConfigured() throws IOException {
        testFilter(
            builder -> builder.startObject().field("foo.bar", "test").endObject(),
            builder -> builder.startObject().field("foo.bar", "test").endObject(),
            singleton(randomFrom("foo.*", "*.bar", "f*.bar", "foo.*ar", "*.*")),
            emptySet(),
            true
        );
    }
    public void testDotInExcludedFieldNamePatternUnconfigured() throws IOException {
        testFilter(
            builder -> builder.startObject().field("foo.bar", "test").endObject(),
            builder -> builder.startObject().field("foo.bar", "test").endObject(),
            emptySet(),
            singleton(randomFrom("foo.*", "foo.*ar")),
            false
        );
    }
    public void testDotInExcludedFieldNamePatternConfigured() throws IOException {
        testFilter(
            builder -> builder.startObject().endObject(),