Data redundancy with a single nested level vs multilevel nested document

Is it better to have a data redundancy with single nested object or maintain multilevel nested document?

There are performance concerns when nested types are used, as per elasticsearch documentation Nested field type | Elasticsearch Guide [7.13] | Elastic

In the below data Scenario#1-> lineLevelDetails (single level nested)captures line, shipment and carton information.
Scenario#2-> Shipment(nested) and carton (nested) details are multi-level nested.

Can experts suggest which scenario is a better option?
Also, updates are expected for lineleveldetails, shipment and cartons data.

Scenario#1:
{
"orderLocation": "xyz",
"orderStatusCode": "6",
"orderId": "2214828263 ",
"lineLevelDetails": [
{
"lineId": "1",
"shipmentId": "1",
"lineStatusCode": "3",
"shipmentStatusCode": "3",
"shipmentStatusDesc": "",
"deliveryStatus": "",
"deliveryStatusTs": "",
"deliveryTrackingNumber": "",
"cartonNumber": 1234
},
{
"lineId": "2",
"shipmentId": "1",
"lineStatusCode": "3",
"shipmentStatusCode": "3",
"shipmentStatusDesc": "",
"deliveryStatus": "",
"deliveryStatusTs": "",
"deliveryTrackingNumber": "",
"cartonNumber": 4567
},
{
"lineId": "3",
"shipmentId": "1",
"lineStatusCode": "3",
"shipmentStatusCode": "3",
"shipmentStatusDesc": "",
"deliveryStatus": "",
"deliveryStatusTs": "",
"deliveryTrackingNumber": "",
"cartonNumber": 3333
}
]
}

Scenario#2:
{
"orderLocation": "xyz",
"orderStatusCode": "6",
"orderId": "2214828263 ",
"lineLevelDetails": [
{
"lineId": "1",
"lineStatusCode": "3"
},
{
"lineId": "2",
"lineStatusCode": "3"
},
{
"lineId": "3",
"lineStatusCode": "3",
}
],
"shipment": [ {
"shipmentId": "1",
"shipmentStatusCode": "3",
"shipmentStatusDesc": "",
"deliveryStatus": "",
"deliveryStatusTs": "",
"deliveryTrackingNumber": "",
"cartons":[ {
"lineId": 1,
"cartonNumber": 1234
},{
"lineId": 2,
"cartonNumber": 4567

    }]
}, 
{
  "shipmentId": "2",
  "shipmentStatusCode": "4",
  "shipmentStatusDesc": "",
  "deliveryStatus": "",
  "deliveryStatusTs": "",
  "deliveryTrackingNumber": "",
  "lines":[ {
    "lineId": 3,
    "cartonNumber": 3333
    }]
  }, 
  }]

}

How many nested objects at different levels does an average document have in the two scenarios? What is the maximum size/number of nested objects? How frequently is some part of a document updated or added to?

  1. How many nested objects at different levels does an average document have in the two scenarios?
    Scenario#1:
    lineleveldetails- array of 5 objects (contains shipment and carton information).

Scenario#2:
lineleveldetails - array of 5 objects (doesn't contain shipment and carton information).
shipments - array of 2 objects.
cartons- (nested under shipments) array of 2 objects.

  1. What is the maximum size/number of nested objects?
    Scenario#1:
    Number of nested objects is 1, only lineleveldetails.

Scenario#2:
Number of nested objects is 3 with below structure.
lineleveldetails
shipments
---cartons

  1. How frequently is some part of a document updated or added to?
    Between each update time duration can be several hours to days.
    Scenario#1:
    lineleveldetails- 4 updates to linestatuscode and 4 updates to shipmentstatuscode. In shipmentstatuscode update scenario, we might update more than 1 more line object as shipment information is redundant across lines.

Scenario#2:
lineleveldetails - 4 updates to linestatuscode .
shipments - 4 updates to shipmentstatuscode.

@Christian_Dahlqvist ^^

If the number of nested objects is low and the documents are not frequently updated I suspect whichever structure that best supports your queries is the one to go with.

@Christian_Dahlqvist Thanks for your reply.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.