I have a query which is significantly faster if I run it against a field containing a timestamp in seconds instead of milliseconds.
Query 1- uses timestampMilliseconds
, averages 500ms to execute:
{
index: 'events',
body: {
query: {
bool: {
filter: {
and: [
{ term: { userId: ... } },
{ range: { timestampMilliseconds: { lt: ... } } }
]
}
}
}
},
sort: 'timestampMilliseconds:desc',
size: 300,
requestTimeout: Infinity
}
Query 2 - uses timestampSeconds
, averages 30ms to execute:
{
index: 'events',
body: {
query: {
bool: {
filter: {
and: [
{ term: { userId: ... } },
{ range: { timestampSeconds: { lt: ... } } }
]
}
}
}
},
sort: 'timestampSeconds:desc',
size: 300,
requestTimeout: Infinity
}
Those two fields are defined as:
timestampMilliseconds: {
type : 'date',
format: 'epoch_millis'
},
timestampSeconds: {
type: 'date',
format: 'epoch_second'
},
Any ideas why this might be the case?
Removing the sort
clauses doesn't seem to make any real difference to the execution time.