# Nested object inside nested object

**URL:** <https://discuss.elastic.co/t/nested-object-inside-nested-object/132267>\
**Category:** Elasticsearch\
**Created:** [May 17, 2018, 7:29am UTC](https://discuss.elastic.co/t/nested-object-inside-nested-object/132267 "2018-05-17T07:29:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasad.ram1431](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@prasad.ram1431](https://discuss.elastic.co/u/prasad.ram1431)\
**Post date:** [May 17, 2018, 7:29am UTC](https://discuss.elastic.co/t/nested-object-inside-nested-object/132267/1 "2018-05-17T07:29:13Z")

</div>

Hi All,

I am facing problem with below data format.

```
PUT personal/user/1
    {
    	"userinfo": {
    		"users": [{
    				"uname": "ram",
    				"age": 25,
    				"address": [{
    					"town": "ct",
    					"city": "ap"
    				}]
    			},
    			{
    				"uname": "ramesh",
    				"age": 28,
    				"address": [{
    					"town": "ctx",
    					"city": "ap"
    				}, {
    					"town": "st",
    					"city": "hyd"
    				}]
    			}
    		]
    	}
    }

```

Below is the mapping file which I created,

```
PUT personal
{
	"mappings": {
		"user": {
			"properties": {
				"userinfo": {
					"properties": {
						"users": {
							"type": "nested",
							"properties": {
								"address": {
									"type": "nested",
									"properties": {
										"town": {
											"type": "text",
											"fields": {
												"keyword": {
													"type": "keyword",
													"ignore_above": 256
												}
											}
										},
										"city": {
											"type": "text",
											"fields": {
												"keyword": {
													"type": "keyword",
													"ignore_above": 256
												}
											}
										}
									}
								},
								"uname": {
									"type": "text",
									"fields": {
										"keyword": {
											"type": "keyword",
											"ignore_above": 256
										}
									}
								},
								"age": {
									"type": "long"
								}
							}
						}
					}
				}
			}
		}
	}
}

```

Now I want the document which contains below validation.  
uname = "ramesh" and town = "ctx" and city = "ap", i should get a document  
uname = "ramesh" and town = "ct" and city = "ap", i should not get document  
uname = "ramesh" and town = "ctx" and city = "hyd", i should not get document.

Could you please suggest me for writing query for this scenario.

Thanks,  
GRP

---

<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:** [June 14, 2018, 7:29am UTC](https://discuss.elastic.co/t/nested-object-inside-nested-object/132267/2 "2018-06-14T07:29:26Z")

</div>

Closed on June 14, 2018, 7:29am UTC

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