# Nested Query not working

**URL:** https://discuss.elastic.co/t/nested-query-not-working/377093
**Category:** Elasticsearch
**Created:** [April 14, 2025, 7:01am UTC](https://discuss.elastic.co/t/nested-query-not-working/377093 "2025-04-14T07:01:12Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![I.am\_mohit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/i.am_mohit/32/142608_2.png) [@I.am\_mohit](https://discuss.elastic.co/u/I.am_mohit)
#### Post date: [April 14, 2025, 7:01am UTC](https://discuss.elastic.co/t/nested-query-not-working/377093/1 "2025-04-14T07:01:12Z")

</div>

```auto
 public class Calendars
 {
     public decimal? NightlyPrice { get; set; }
     public bool? Availability { get; set; }
     public List<CalendarDates> Dates{ get; set; }
 }
 public class CalendarDates
{
    public DateTime? FromDate { get; set; }
    public DateTime? ToDate { get; set; }
}

```

This is my dto, and I have nested mapping for CalendarDates model  
I have written query below to fetch data but no result out

```auto
DateTime sdate = new DateTime(2025, 03, 03);
DateTime edate = new DateTime(2025, 03, 04);
int[] searchTerm = [7515];
var response = await _elasticClient.SearchAsync<Calendars>(s => s
    .Index(indexName)
    .From(0)
    .Size(1200)
    .Query(q => q
        .Bool(b => b
            .Must(m => m
                .Terms(ts => ts
                    .Field(f => f.PropertyId)
                    .Terms(BuildTermsQueryField(searchTerm))
                )
            ).Filter(f => f
                .Nested(n => n
                    .Path(p => p.BookingPalCalendarDates)
                        .Query(q => q
                            .Bool(b => b
                                .Must(m => m.Range(rr => rr
                                    .DateRange(dr => dr
                                    .Field("CalendarDates.FromDate") // assumes StartDate is of type DateTime
                                        .Gte(sdate) // specify your lower bound
                                            .Lte(edate)
                                            )
                                    )
                                )
                                )
                            )
                        )
                )
            )
        )
    );

```

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [April 14, 2025, 9:11am UTC](https://discuss.elastic.co/t/nested-query-not-working/377093/2 "2025-04-14T09:11:00Z")

</div>

Welcome!

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can **copy and paste in Kibana dev console** , click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Have a look at the [Elastic Stack and Solutions Help · Forums and Slack | Elastic](https://elastic.co/community/help) page. It contains also lot of useful information on how to ask for help.
