# How to get nested type array length?

**URL:** <https://discuss.elastic.co/t/how-to-get-nested-type-array-length/176319>\
**Category:** Elasticsearch\
**Created:** [April 11, 2019, 5:26am UTC](https://discuss.elastic.co/t/how-to-get-nested-type-array-length/176319 "2019-04-11T05:26:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vu\_Nguyen\_Van](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vu_nguyen_van/32/43901_2.png) [@Vu\_Nguyen\_Van](https://discuss.elastic.co/u/Vu_Nguyen_Van)\
**Post date:** [April 11, 2019, 5:26am UTC](https://discuss.elastic.co/t/how-to-get-nested-type-array-length/176319/1 "2019-04-11T05:26:04Z")

</div>

Hi, i have a document as follow 🙂{  
"took": 0,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 4,  
"max\_score": 1,  
"hits": [  
{  
"\_index": "people",  
"\_type": "person",  
"\_id": "tqK1CmoBpUyg-koVON3h",  
"\_score": 1,  
"\_source": {  
"fullName": "Person 3",  
"totalSalary": 200000,  
"positions": [  
{  
"name": "Teacher",  
"isCurrentPosition": false,  
"expirationDate": "2019-10-11T11:43:29.8168467+07:00",  
"hasAverageLimitStatistic": false,  
"averageMonthLimit": 3,  
"salary": 0  
},  
{  
"name": "TTTT",  
"isCurrentPosition": false,  
"expirationDate": "2019-10-11T11:43:29.8168467+07:00",  
"hasAverageLimitStatistic": false,  
"averageMonthLimit": 2,  
"salary": 0  
}  
]  
}  
},  
{  
"\_index": "people",  
"\_type": "person",  
"\_id": "tKK1CmoBpUyg-koVON3h",  
"\_score": 1,  
"\_source": {  
"fullName": "Person 1",  
"totalSalary": 100000,  
"positions": [  
{  
"name": "Janitor",  
"isCurrentPosition": false,  
"expirationDate": "0001-01-01T00:00:00",  
"monthsWorked": 3,  
"hasAverageLimitStatistic": true,  
"averageMonthLimit": 5,  
"salary": 0  
}  
]  
}  
},  
{  
"\_index": "people",  
"\_type": "person",  
"\_id": "taK1CmoBpUyg-koVON3h",  
"\_score": 1,  
"\_source": {  
"fullName": "Person 2",  
"totalSalary": 150000,  
"positions": [  
{  
"name": "Coach",  
"isCurrentPosition": false,  
"expirationDate": "0001-01-01T00:00:00",  
"hasAverageLimitStatistic": true,  
"averageMonthLimit": 5,  
"salary": 0  
}  
]  
}  
},  
{  
"\_index": "people",  
"\_type": "person",  
"\_id": "t6K1CmoBpUyg-koVON3h",  
"\_score": 1,  
"\_source": {  
"fullName": "Person 4",  
"totalSalary": 250000,  
"positions": [  
{  
"name": "Head",  
"isCurrentPosition": false,  
"expirationDate": "2021-04-11T11:43:29.8168467+07:00",  
"hasAverageLimitStatistic": false,  
"averageMonthLimit": 1,  
"salary": 0  
}  
]  
}  
}  
]  
}  
}

i want to get a list of people that have more positions than 1 . this is an array.i've tried as below  
var searchResponse = client.Search(s =\> s.Type("person")  
.Query(q =\> q.Nested(n =\>  
n.Path(p =\> p.Positions)//  
.Query(qr =\> qr.Script(scr =\> scr.Source("doc['positions'].values.lenght \> 1")  
.Lang("painless"))))));

but it give me an error

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/3/3393785c3a8785b88ed8ea7cb47ef167888ed8c6.png)

Does any one have solutions for this problem ?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 11, 2019, 2:29pm UTC](https://discuss.elastic.co/t/how-to-get-nested-type-array-length/176319/2 "2019-04-11T14:29:05Z")

</div>

I think the easiest way would be to store the length of the array as an additional field in the document. You can achieve this using the [script processor](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/script-processor.html)

--Alex

---

<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 9, 2019, 2:29pm UTC](https://discuss.elastic.co/t/how-to-get-nested-type-array-length/176319/3 "2019-05-09T14:29:09Z")

</div>

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