Painless get date today

Since there is not a lot of information around painless yet I hope there is someone here with experience in it.
I want to filter all messages that happend on the same day of the week. So like today I want all messages that happend on a wednesday.
So is there a way to get todays Date?
This is my script but should get changed.
(I would like to do the same with the hour)

GET _search
      "query": {
        "bool": {
          "filter": {
            "script": {
              "script": "doc['@timestamp'].date.dayOfWeek =="

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.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.