Understanding use case for nested field types

Opensearch documentation https://opensearch.org/docs/latest/field-types/supported-field-types/nested/

provides an example where a search will fail because arrays are flattened when stored:

PUT testindex1/_doc/100
{ 
  "patients": [ 
    {"name" : "John Doe", "age" : 56, "smoker" : true},
    {"name" : "Mary Major", "age" : 85, "smoker" : false}
  ] 
}

becomes:

{
    "patients.name" : ["John Doe", "Mary Major"],
    "patients.age" : [56, 85],
    "patients.smoker" : [true, false]
}

Rather than use nested data types (which introduces a number of issues), why not make separate entries??

PUT testindex1/_doc/100
{ 
  "patients": {"name" : "John Doe", "age" : 56, "smoker" : true}
}

PUT testindex1/_doc/100
{ 
  "patients": {"name" : "Mary Major", "age" : 85, "smoker" : false}
}

Nested fields can be used when you have an array of objects and need to maintain relationships between the values in each object. The nested data type prevents issues with cross-object field matching, which occurs in regular object fields.

The nested query searches nested field objects as if they were indexed as separate documents. If an object matches the search, the nested query returns the root parent document.

Thanks for replying,

I’m trying to understand why use a nested data structure when you can avoid it and simply make separate entries as I indicated above. Are there specific use cases where nested structures are advantageous?

I hope these two examples will be helpful for you: