[BUG] Calling getMillis() in Painless script is slow
See original GitHub issueDescribe 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. https://github.com/elastic/elasticsearch/issues/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
Issue Analytics
- State:
- Created a year ago
- Comments:10 (2 by maintainers)
Top GitHub Comments
@dblock 👍 to that, will create an issue + change
Got it, I am not sure there are any other way to get these deprecation warning without accessing logs or changing configuration. You could probably open a case with AWS regarding that, those are vendor-specific constraints apparently.