I have a strange problem when I make queries in date range
Mapping index
. . .
"datetime": {
"type": "date",
"format": "epoch_second||yyyy-MM-dd HH:mm:ss",
"ignore_malformed": true
},
. . .
Query without range
{
"size": 1000,
"query": {
"bool": {
"must": [
{
"term": {
"log_id": {
"value": 9908016
}
}
},
{
"range": {
"datetime": {
"gte": 1670581920,
"time_zone": "Z",
"boost": 1
}
}
}
],
"boost": 1
}
},
"_source": false,
"fields": [
{
"field": "log_id"
},
{
"field": "datetime",
"format": "strict_date_optional_time_nanos"
}
],
"sort": [
{
"_doc": {
"order": "asc"
}
}
],
"track_total_hits": -1
}
Result
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"max_score": null,
"hits": [
{
"_index": "analyzers-2022111701",
"_id": "McJx9oQByZyUKY4qIpWk",
"_score": null,
"fields": {
"log_id": [
"9908016"
],
"datetime": [
"2022-12-09T10:32:00.000Z"
]
},
"sort": [
9697694
]
}
]
}
}
Query with range
{
"size": 1000,
"query": {
"bool": {
"must": [
{
"term": {
"log_id": {
"value": 9908016
}
}
},
{
"range": {
"datetime": {
"gte": 1670581920,
"lte": 1670583333,
"time_zone": "Z",
"boost": 1
}
}
}
],
"boost": 1
}
},
"_source": false,
"fields": [
{
"field": "log_id"
},
{
"field": "datetime",
"format": "strict_date_optional_time_nanos"
}
],
"sort": [
{
"_doc": {
"order": "asc"
}
}
],
"track_total_hits": -1
}
Result empty
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"max_score": null,
"hits": []
}
}
But if use datetime in format yyyy-MM-dd HH:mm:ss in query works fine.
{
"size": 1000,
"query": {
"bool": {
"must": [
{
"term": {
"log_id": {
"value": 9908016
}
}
},
{
"range": {
"datetime": {
"gte": "2022-12-09 10:32:00",
"lte": "2022-12-09 10:55:33",
"time_zone": "Z",
"boost": 1
}
}
}
],
"boost": 1
}
},
"_source": false,
"fields": [
{
"field": "log_id"
},
{
"field": "datetime",
"format": "strict_date_optional_time_nanos"
}
],
"sort": [
{
"_doc": {
"order": "asc"
}
}
],
"track_total_hits": -1
}
Good result
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"max_score": null,
"hits": [
{
"_index": "analyzers-2022111701",
"_id": "McJx9oQByZyUKY4qIpWk",
"_score": null,
"fields": {
"log_id": [
"9908016"
],
"datetime": [
"2022-12-09T10:32:00.000Z"
]
},
"sort": [
9697694
]
}
]
}
}
I don't understand why this behavior
This forces me to rephrase my calls from my app (PHP) and drives me crazy.