# ElasticSearch - Getting paged result in a nested list (nested pagination)

**URL:** <https://discuss.elastic.co/t/elasticsearch-getting-paged-result-in-a-nested-list-nested-pagination/82267>\
**Category:** Elasticsearch\
**Created:** [April 13, 2017, 9:53am UTC](https://discuss.elastic.co/t/elasticsearch-getting-paged-result-in-a-nested-list-nested-pagination/82267 "2017-04-13T09:53:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![YPerry](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@YPerry](https://discuss.elastic.co/u/YPerry)\
**Post date:** [April 13, 2017, 9:53am UTC](https://discuss.elastic.co/t/elasticsearch-getting-paged-result-in-a-nested-list-nested-pagination/82267/1 "2017-04-13T09:53:39Z")

</div>

I have the following Json that describes a country-city (1:n) relation

```
{
	"country": [
		{
			"id": 1,
			"name": "Country1",
			"city": [
				{"id": 1, "name": "City1"},
				{"id": 2,"name": "City2"}
			]
		}, {
			"id": 2,
			"name": "Country2",
			"city": [
				{"id": 3,"name": "City3"},
                {"id": 4,"name": "City4"}
			]
		}, {
			"id": 3,
			"name": "Country3",
			"city": [
				{"id": 5,"name": "City5"},
                {"id": 6,"name": "City6"}
			]
		}
	]
}

```

I have loaded it into an ES map with 3 documents of the three countries.  
I have added nested property in the city index

```
...
 "city": {
             "type": "nested",
...

```

I want to query all cities and get a paged result.

1. For instance 3 hits will return city1, city2, city3
2. I want to filter by country name

I tried

```
GET /127.0.0.1:9200/country_city/_search
{
    "from": 0,
    "size": 2,
    "fields": [
       "city.id", "city.name"
    ]
}

```

and

{  
"query": {  
"nested": {  
"path": "city",  
"query": {  
"match\_all": {}  
},  
"inner\_hits": {  
"from": 0,  
"size": 2  
}  
}  
},  
"fields": [  
"[city.id](http://city.id)",  
"[city.name](http://city.name)"  
]  
}

But the first returned two 4 cities instead of 2.  
(2 countries have 2 cities each)  
The second returned all documents  
(although size is 2 in the request)

How Can I set a page size of the nested object?

---

<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:** [May 11, 2017, 10:04am UTC](https://discuss.elastic.co/t/elasticsearch-getting-paged-result-in-a-nested-list-nested-pagination/82267/2 "2017-05-11T10:04:48Z")

</div>

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