A cup of coffee or a glass of wine helps maintain "good" bacteria in the gut but whole milk or a calorie packed diet is bad, a new study found.
It has long been established that whatever we eat affects the trillions of bacteria in our intestines.
This colony consists of "good" bacteria which have anti-inflammatory properties and "bad" ones that promote inflammation.
Maintaining the balance is important for health.
A Dutch study found people who regularly consume yogurt or buttermilk have a greater diversity of gut bacteria.
Coffee and wine can increase the diversity as well, while whole milk or a high-calorie diet can decrease it.
Unlike other studies, it looked at normal people rather than those with illnesses as part of the LifeLines programme which monitors the health of 165,000 residents of the Northern Netherlands.
It collected questionnaires on diet, medicine prescriptions and health of 1,100 people as well as analysing their gut DNA from frozen stools.
Professor of Human Genetics Dr Cisca Wijmenga of the University of Groningen said: "Normally researchers only investigate one particular region of DNA in which different groups of bacteria can be distinguished
"We have mapped all the bacterial DNA to gain much more detailed information about bacteria types.
"You see, for example, the effect of diet in the gut."
The DNA analysis made it possible to examine which factors impact the diversity of the microbiome.
Dr Alexandra Zhernakova said: "In total we found 60 dietary factors that influence the diversity.
"What these mean exactly is still hard to say. But there is a good correlation between diversity and health: greater diversity is better."
Beyond diet, at least 19 different kinds of medicine - some of which are widely used -have an impact on microbiome diversity.
An earlier study showed antacids decreased this diversity, while antibiotics and the diabetes drug metformin also have an effect.
Prof Wijmenga said: "Disease often occurs as the result of many factors.
"Most of these factors, like your genes or your age, are not things you can change.
"But you can change the diversity of your microbiome through adapting your diet or medication. When we understand how this works, it will open up new possibilities."
The study was published in the journal Science.