2

I'm trying to make a script within my rescore function to check if the bibliographic release date (doc['bibliografische_verschijningsdatum']), is the same as the commercial release date (doc['verschijningsdatum']).

AND the doc['verschijningsjaar'].value == new Date.getYear()

How can I get the year of todays date in painless?

"script_score": {
          "script": "((doc['verschijningsdatum'] == doc['bibliografische_verschijningsdatum']) && (doc['verschijningsjaar'].value == new Date().getYear()) ? 1 : 0)"
        }
      }

1 Answer 1

2

Your question has already been asked on the elastic forum. The official answer, at least from a member of the elastic team, is the following, (emphasis is mine):

Painless intentionally doesn't have any access to now style variables so they can be better cached. The current recommendation is for you to send now style variables in over scripts params.

BTW, you should know that this query isn't able to take advantage of the index at all. It'll have to load the @timestamp field for every document and compare it. This much much slower than extracting the day of the week on ingest and adding it to the document.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.