question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Calling getMillis() in Painless script is slow

See original GitHub issue

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. 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:closed
  • Created a year ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
retacommented, May 16, 2022

@dblock 👍 to that, will create an issue + change

0reactions
retacommented, May 16, 2022

Amazon OpenSearch Service

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Painless script, get error dynamic method [java.lang.Long ...
So when i run this script, doc['date_updated'].value.getMillis() > params.one_day ? 1.9. i get the error dynamic method [java.lang.
Read more >
Getting Started with Painless - Fossies
Painless is a simple, secure scripting language designed specifically for use with Elasticsearch. It is the default scripting language for ...
Read more >
docs/painless/painless-guide - elasticsearch - Gitlab Kveer
The following example uses a Painless script to sort the players by their ... if a document is missing a value, you can...
Read more >
How We Improved Our Performance Using ElasticSearch ...
We were aware of an alternative to painless script, ES plugins , which ... A script plugin is essentially a “run()” function from...
Read more >
JDK-8141210 Very slow loading of JavaScript file with ... - Bug ID
REPRODUCIBILITY : This bug can be reproduced always. ... f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found