-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Describe the bug
We had a sorting script that called getMillis() on a date field. We noticed that the script was unusually slow for queries that matched a large number of results, and determined that getMillis() was the bottleneck. Removing that call resulted in a 10-fold speed-up.
I found this bug report for ElasticSearch 6.5.0, which looks very similar to what I ran into. It says that the bug was fixed; maybe the fix never made it into OpenSearch, maybe the bug came back. elastic/elasticsearch#35754
I had good results with the work-around suggested in that report (replacing getMillis() with toInstant().toEpochMilli()).
To Reproduce
On an index with a datetime field called originalDate, and a large number of documents (a million or more), run this search:
{
"_source": ["id","originalDate"],
"sort": {
"_script": {
"type": "number",
"order": "asc",
"script": {
"source": "return doc[\"originalDate\"].value.getMillis();"
}
}
}
}
Host/Environment:
Amazon OpenSearch service v1.0