How to query DataOptionaTime field

Can somebody explain me how to format date for Elastic query if I want to get events which are gt than YYYY-MM-DD\T00:00:00 ? The ES date mapping format is dateOptionalTime . ES version is 2. I am doing it in PHP script which generates this query:

{
    "sort": {
        "publishDate": "desc"
    },
    "query": {
        "bool": {
            "filter": [
                {
                    "range": {
                        "publishDate": {
                            "lte": "2018-10-29",
                            "gt": "2018-10-22T00:00:00"
                        }
                    }
                },
                {
                    "terms": {
                        "ico": [
                            31322832,
                            31400396
                        ]
                    }
                }
            ]
        }
    }
}

The first date 2018-10-29 works fine but the second 2018-10-22T00:00:00 throws an error: Invalid format: "2018-10-22T00:00:00" is malformed at "T00:00:00" I found the format on this page and dont know what is wrong with that.

The second question is if this is the way to search dates when I need to check hours and minutes.

Teh problem was the request leads to two indexes and I checked only one of them. The second one has mapping like "publishDate": {"type": "date", "format": "date"}

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