Study done on flies. How it happens is not clear, but gut bacteria do seem to affect their behaviour.
How Gut Bacteria Tell Their Hosts What to Eat
By suppressing or increasing cravings, microbes help the brain decide what foods the body “needs.”
getpocket.com