I hate hardcoding dynamic things. Sooner or later those thing break. I have data with fields ... forecast_2020=400, forecast_2021=500, forecast_2022=650, forecast_2023=800 ... and in some search I need to use the correct forecast for the current year. What I could do is ...
| eval year=strftime(now(),"%Y"),
forecast=case(year==2021, forecast_2021,
year==2022, forecast_2022,
year==2023, forecast_2023,
1==1, 0) This definitely results in problems in 2024; by then I will have a field forecast_2024 but nobody will remember to update the search. I'd rather use something along these lines: ...
| eval year=strftime(now(),"%Y"),
forecast=coalesce(forecast_{year}, 0) However, the {} trick can only be used on the left hand side in eval. Is there any similar cool trick which works on the right hand side?
... View more