# ElasticSearch Nested Objects

**URL:** <https://discuss.elastic.co/t/elasticsearch-nested-objects/2041>\
**Category:** Elasticsearch\
**Created:** [June 5, 2015, 8:44pm UTC](https://discuss.elastic.co/t/elasticsearch-nested-objects/2041 "2015-06-05T20:44:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sameerd](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@sameerd](https://discuss.elastic.co/u/sameerd)\
**Post date:** [June 5, 2015, 8:44pm UTC](https://discuss.elastic.co/t/elasticsearch-nested-objects/2041/1 "2015-06-05T20:44:48Z")

</div>

I have a question on nested and parent/child objects.

Below are my sample nested documents –

DocumentID: 1

```
{
    "UserID": 1,
    "FirstName": "User1 First",
    "LastNameName": "User1 Last",
    "Assignments": [
        {
            "Role": "Role1",
            "Permission": "P1",
            "Value": "V1"
        },
        {
            "Role": "Role2",
            "Permission": "P2",
            "Value": "V2"
        }
    ]
}

```

DocumentID: 2

```
{
    "UserID": 2,
    "FirstName": "User2 First",
    "LastNameName": "User2 Last",
    "Assignments": [
        {
            "Role": "Role1",
            "Permission": "P1",
            "Value": "V1"
        }
    ]
}

```

Below are my questions –

1. 

```
  Is it mandatory to put “type:nested” for nested field “Assignments”? "Assignments' is an array which will have multiple sub-documents.

```

2. 

```
  We mostly use queryString method for querying on these documents. Our queries generally are like below – 

```

((Assignments.Role=Role1 AND Assignments.Role=Role2) OR (Assignments.Role=Role3 AND Assignments.Role=Role5) OR (Assignments.Role=Role3))  
There can be multiple AND\OR conditions. We get expected results with above query. So do we have to add type:nested for nested field?  
3. Also, if we use parent-child documents then can we add same child (same 'assignments' object in above case) to multiple parents?  
I have gone through below link and it seems that there are few dis-advantages of adding type=nested property for nested field.

> **[Managing Relations Inside Elasticsearch
	  	 | Elastic](https://www.elastic.co/blog/managing-relations-inside-elasticsearch)**
>
> Data in the real world is rarely simple - often times it is a jumble of interlocking relations. How do you represent relational data in Elasticsearch? There are a few mechanisms that can be used to pr...

Request you to please provide your valuable suggestion.

Thanks,  
Sameer

---

<div class="post-metadata">

**Author:** ![mosiddi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mosiddi/32/577_2.png) [@mosiddi](https://discuss.elastic.co/u/mosiddi)\
**Post date:** [September 16, 2015, 7:40am UTC](https://discuss.elastic.co/t/elasticsearch-nested-objects/2041/2 "2015-09-16T07:40:33Z")

</div>

you might like to look @ this thread [Parent/Child functionality](https://discuss.elastic.co/t/parent-child-functionality/2045/2) where the discussion related to nested v/s parent/child happened. though doesn't answer all ur Qs 🙂

---

<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 5, 2017, 11:50pm UTC](https://discuss.elastic.co/t/elasticsearch-nested-objects/2041/3 "2017-07-05T23:50:06Z")

</div>


