Here's what I do. Any search key will turn hlsearch on and <Esc> will turn it off.
vim.on_key(function(char)
if vim.fn.mode() == "n" then
local new_hlsearch = vim.tbl_contains({ "<CR>", "n", "N", "*", "#", "?", "/" }, vim.fn.keytrans(char))
local esc = vim.tbl_contains({ "<Esc>" }, vim.fn.keytrans(char))
if new_hlsearch then
vim.opt.hlsearch = true
elseif esc then
vim.opt.hlsearch = false
end
end
end, vim.api.nvim_create_namespace("auto_hlsearch"))