Date Range filter is not working ? NEST C# MVC.NET

hi every one
Why date Range filter is not working in my code:

        public static DateRangeQuery GetSearchFromDate(int DayFrom, int DayTo, int MonthFrom, int MonthTo, int YearFrom, int YearTo, string fieldName)
        {
            DateTime dateFrom = new(YearFrom, MonthFrom, DayFrom, 0,0,0);
            DateTime dateTo   = new(YearTo, MonthTo, DayTo, 0,0,0);

            return new DateRangeQuery
            {
                Boost = 1.1,
                Field = myfieldName,
                GreaterThanOrEqualTo = dateFrom,
                LessThanOrEqualTo = dateTo,
                TimeZone = "+01:00",
                Format = "yyyy/MM/dd"
            };
        }
        [Date]
        public DateTime myfieldName{ get; set; }
  • sample of date in the elastic:
"myfieldName": "1957-01-10T00:00:00",

Hi @Samer_Abdelwahed

What error happen?

You try "format": "yyyy-MM-dd'T'HH:mm:ss" ?

Also no results. document count = 0 , Total = 0
While there are documents matching the date
many thanks

What values range you are using?

many thanks :slightly_smiling_face:

this date "1957-01-10T00:00:00" not between 2000-02-01T00:00:00 and 2023-10-05T00:00:00.

This example workds:

POST idx_date/_doc
{
 "myfieldName": "2021-01-10T00:00:00"
}

GET idx_date/_search
{
  "query": {
    "range": {
      "myfieldName": {
        "gte": "2000-02-01T00:00:00",
        "lte": "2023-10-05T00:00:00",
        "time_zone": "+01:00", 
        "format": "yyyy-MM-dd'T'HH:mm:ss"
      }
    }
  }
}

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