I have the same issue sometimes. Everyone is different, but for me I find foods with skins or membranes often cause gas for me, such as onions, peas, beans, etc. Onions are easily the worst for me, so I will often avoid having too much onion in my dinner if I can help it, especially if I know I'll be going to bed earlier than usual. I have an alarm set for 3am or 4am every night whilst I have my ileostomy just to make sure that I at least check that the bag isn't too full with either gas or output, and will often get up during the night to empty it. In my five and a half months of having an ileostomy, I've only ever had the bag leak twice, and one of those times I woke up just before it leaked and managed to get into the shower before it properly came off. I also use bags that have a built-in gas filter, though I question how effective it is sometimes. I was never taught how to burp the bag, and so I have never bothered trying it as I don't want to make a mess.
Having broken sleep can be tiring and frustrating sometimes, but I'd rather that than waking up to the bag having come off during the night. To me, not setting an alarm is like playing with fire. Obviously this method isn't for everyone, but I'm a very structured person and so I find it very useful to have that safety net in place.
Many hospitals either give you a list of foods that often have certain effects (mine did), or their website will have a list. A quick Google search will yield plenty of results. Here's a link from my state government outlining all sorts of info about food and ileostomies: https://www.health.qld.gov.au/__data/assets/pdf_file/0026/152558/gastro_ileostomy.pdf. If you scroll down to the "Will I experience any problems?" section, there's a list of examples of foods that have certain effects, such as gas or odour.
Overall, I don't avoid any specific food other than nuts. Everything in moderation, as they say. Good luck with it. I hope you found out a solution that works for you.