Date Range filter is not working in the elasticsearch

The Query i'm using

{"query":
{
"filtered":{"query":{"match_all":{}},
"filter":{

"and":[
{ "range":
{
"created_date":{"gte":"2010-05-22","lte":"2012- 05-22", "format":"yyyy-mm-dd"
}
}
},{"not":{"term":{"flag":"Y"}}}]

}}
}
}

the created_date format is "2010-02-19T21:02:02.000Z"

I have given created_date as the "Date" in the mapping file.
Can anyone please help me out in this solving this issue.

You have a space in lte part. Is that a typo?

It'd be better if you can send a full script which reproduces your issue.

{  
   "query":{  
  "filtered":{  
     "query":{  
        "match_all":{  

        }
     },
     "filter":{  
        "and":[  
           {  
              "range":{  
                 "created_date":{  
                    "gte":"2010-05-22",
                    "lte":"2012-05-22",
                    "format":"yyyy-mm-dd"
                 }
              }
           },
           {  
              "not":{  
                 "term":{  
                    "end_dated_flag":"Y"
                 }
              }
           }
        ]
     }
  }
   },
   from:0,
   size:50
}

I see records with the date 2010-02-19 in the result

It's super important to understand exactly what you are doing.
Also, please format your code. It makes easier to read.

I'm sorry dadoonet for not indenting the JSON. I have updated the JSON with the proper format. There is no space in the lte value.

I have found out the issue.

The issue was the date format : "yyyy-mm-dd"
It should be "yyyy-MM-dd"

Thank you

2 Likes