# Can we use nested object in the parent-child relationship in elasticsearch?

**URL:** <https://discuss.elastic.co/t/can-we-use-nested-object-in-the-parent-child-relationship-in-elasticsearch/237625>\
**Category:** Elasticsearch\
**Created:** [June 18, 2020, 11:32am UTC](https://discuss.elastic.co/t/can-we-use-nested-object-in-the-parent-child-relationship-in-elasticsearch/237625 "2020-06-18T11:32:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharathnasa](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@sharathnasa](https://discuss.elastic.co/u/sharathnasa)\
**Post date:** [June 18, 2020, 11:32am UTC](https://discuss.elastic.co/t/can-we-use-nested-object-in-the-parent-child-relationship-in-elasticsearch/237625/1 "2020-06-18T11:32:59Z")

</div>

i'm creating the mapping in elasticsearch. I have a four objects such as customer, promotion, product and agreement

1. Customer - parent and promotion - child(child of customer)
2. Promotion - parent and product - child(child of Promotion)
3. Promotion - parent and agreement - child(child of Promotion)

i'm creating the mapping in elastic search. I have a four objects such as customer, promotion, product and agreement

1. Customer - parent and promotion - child(child of customer)
2. Promotion - parent and product - child(child of Promotion)
3. Promotion - parent and agreement - child(child of Promotion)

I have created the mapping in the console as shown below for which i need to same using Java API.

```auto
PUT /promotionsearch
{
  "mappings": {
    "properties": {
      "customer":{
        "properties": { 
          "id":{
            "type": "text"
          },
          "externalId":{
            "type":"text"
          },
          "businessSystem":{
            "type": "integer"
          },
          "fullName":{
            "type":"text"
          }
        }
      },
      "promotion":{
        "properties": {
           "id":{
            "type": "text"
          },
          "externalId":{
            "type":"text"
          },
          "businessSystem":{
            "type": "integer"
          },
          "promotionDescription":{
            "type":"text"
          },
          "promotionType":{
            "type":"keyword"
          },
          "promotionStatus":{
            "type":"keyword"
          },
          "promotionCustomer":{
            "type":"text"
          },
          "promotionProducts":{
            "type":"nested"
          }
        }
      },
      "product":{
        "properties": {
          "id":{
            "type":"text"
          },
          "externalId":{
            "type":"text"
          },
          "businessSystem":{
            "type":"integer"
          },
          "productDescription":{
            "type":"text"
          }
        }
      },
      "rebateagreement":{
        "properties": {
           "id":{
            "type":"text"
          },
          "businessSystem":{
            "type":"integer"
          },
          "validFrom":{
            "type":"date",
            "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
          },
          "validTo":{
             "type":"date",
            "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
          }
        }
      },
      "promotion_search_join":{
        "type": "join",
        "relations":{
          "customer":"promotion",
          "promotion":["product", "rebate"]
        }
      }
    }
  }
}

```

My question is if you see the Promotion mapping, it has field **promotionProducts** which is actually a list which contains the product. So i have made it as Type **Nested**.

1. Is it valid to have a nested objects like in parent-child relations?
2. Does this adds more complexity while querying?

I did explored the document of ES, could find anything related to this scenario. Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 16, 2020, 11:33am UTC](https://discuss.elastic.co/t/can-we-use-nested-object-in-the-parent-child-relationship-in-elasticsearch/237625/2 "2020-07-16T11:33:03Z")

</div>

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