Kindly open the Elasticsearch documentation and search for “heap-size” and you’ll find your solution.
2-4 GB memory usage for Elasticsearch is absolutely fine.
Unless you have 400 agents plus, I don’t see a reason why the machine would need 32GB memory. 8 to 16 GB should be enough.