# Filtering on a property of the first element in a Nested property array

**URL:** <https://discuss.elastic.co/t/filtering-on-a-property-of-the-first-element-in-a-nested-property-array/279298>\
**Category:** Elasticsearch\
**Created:** [July 21, 2021, 5:46pm UTC](https://discuss.elastic.co/t/filtering-on-a-property-of-the-first-element-in-a-nested-property-array/279298 "2021-07-21T17:46:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sikelela\_Nkohla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sikelela_nkohla/32/78403_2.png) [@Sikelela\_Nkohla](https://discuss.elastic.co/u/Sikelela_Nkohla)\
**Post date:** [July 21, 2021, 5:46pm UTC](https://discuss.elastic.co/t/filtering-on-a-property-of-the-first-element-in-a-nested-property-array/279298/1 "2021-07-21T17:46:27Z")

</div>

We have the following document structure :

"Document" : {  
"arvTreatmentStarted" : "started",  
"followUps" : [  
{  
"followUpDate" : "2012-01-01",  
"arvDrugs" : {  
"dispenseDoseQuantity" : "30",  
"dispenseDoseDaysSupply" : "144"  
},  
"followUpStatus" : "Alive on ART"  
},  
{  
"followUpDate" : "2013-01-01",  
"arvDrugs" : {  
"dispenseDoseQuantity" : "30",  
"dispenseDoseDaysSupply" : "144"  
},  
"followUpStatus" : "Alive on ART"  
}  
]  
}

This document contains a nested property called Follow Ups which is an array of objects. In these objects there is a property called _followUpDate_ .

Business Rule : We need to find the first Follow Up in the follow ups array and check if it's followUpDate is within a particular range and if it is not, exclude the whole Document from the search result set.

As an example if we had the date range 2013 - 2014

- It would include the Document in the result set because the query would consider the followUpDate for the second Follow Up in the list as valid.
- However this should not happen according to the Business rule as the First Follow up has a followUpDate that is not within the date range.

Below is the sample of our nested query

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/8/088eef6ac86e69e4428ec2880a4aa9c5478fdaf0.png)

---

<div class="post-metadata">

**Author:** ![adrian\_floor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adrian_floor/32/77134_2.png) [@adrian\_floor](https://discuss.elastic.co/u/adrian_floor)\
**Post date:** [July 22, 2021, 7:54am UTC](https://discuss.elastic.co/t/filtering-on-a-property-of-the-first-element-in-a-nested-property-array/279298/2 "2021-07-22T07:54:52Z")

</div>

Yes interesting question, I would be interesting in hearing the answers that anyone could come up with

---

<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:** [August 19, 2021, 7:55am UTC](https://discuss.elastic.co/t/filtering-on-a-property-of-the-first-element-in-a-nested-property-array/279298/3 "2021-08-19T07:55:22Z")

</div>

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