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

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",
"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?

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