A bit of sun might help diversify the bugs in your gut, a study published Thursday suggests.

Brief exposure to ultraviolet rays not only bumps up vitamin D levels, but could also lead to a more varied collection of gut bacteria, according to the Frontiers in Microbiology study.

On the surface, sunlight and gut microbes seem to have nothing in common — after all, your gut bacteria are unlikely to find themselves catching some rays.

But the Canadian researchers were interested in studying the effects of UV light on the gut’s microorganisms because low levels of sun exposure, insufficient levels of vitamin D and a lack of microbiome diversity have all been linked to certain inflammatory health conditions, such as inflammatory bowel disease.

“This is the first study to find a direct effect of UVB on intestinal microbes,” said lead study author Else Bosman, a researcher and doctoral candidate in the Department of Experimental Medicine at the University of British Columbia. The findings also point to the important role that vitamin D, which is produced when UV rays hit the skin, appears to play in “maintaining healthy gut microbe composition,” she added.

To explore the impact of sunlight on the microbiome, the researchers recruited 21 healthy women whose average age was 28. At the start of the study, the volunteers’ had their vitamin D levels measured, and also had stool samples examined to determine the makeup of their microbiomes, the collection of microorganisms that populate the gut.

The women were then exposed to a narrow band of UVB rays three times in one week. (UVA and UVB are the two main types of UV light that reach the Earth from the sun.) Because the study took place in winter in Canada, all of the women had little sun exposure otherwise. Some, however, had been taking supplements to keep their vitamin D levels up; most of the women who weren’t supplementing had “insufficient” levels of vitamin D.

At the end of the week, the women had their vitamin D levels and stool samples checked again. Vitamin D levels increased in the majority of the volunteers, even those taking supplements. The women who had low levels of vitamin D at the beginning of the study now had normal levels and, intriguingly, their microbiomes had become more diverse.

“Healthy people tend to have more diverse microbiomes,” Bosman said.

The results might be especially welcomed by people with inflammatory bowel disease, who have trouble absorbing nutrients through their digestive systems, Bosman said. For them, spending some time in the sun might be an effective way to boost vitamin D levels.

Experts said that the new findings were interesting, but cautioned that the number of participants was small.

Future studies should include a lot more volunteers who are randomly assigned to either placebo or UVB exposure, said Dr. Purna Kashyap, an associate professor of medicine, physiology and biomedical engineering and the co-director of the Microbiome Program at the Mayo Clinic.

Still, because the study was done in humans, “we know it’s going to be relevant,” he said.

There have been a number of studies looking at the connection between microbiome composition and a variety of factors, said Dr. Jonathan Jacobs, an assistant professor of medicine at the University of California, Los Angeles, Medical School and the director of the UCLA Microbiome Core.

“What makes this study of potentially greater interest is the intervention with UV exposure,” Jacobs said, adding he doubted anyone in the medical community would recommend sun exposure due to fears of skin cancer.

Still, “there is significant evidence, primarily from animal models, that vitamin D is important for intestinal [health]," he said. Studies have also shown that the microbiomes of people with IBD tend to be lower in diversity, he said.

While the researchers showed that the volunteers’ microbiomes changed, it’s not known whether those changes are good, bad or neutral, Jacobs said. That’s something for further study, he said.

Beyond that, no one knows what the significance is of a low diversity microbiome in patients with IBD, said Dr. Alexander Khoruts, a professor of medicine and the medical director of the Microbiota Therapeutics Program at the University of Minnesota.

It's unclear if the changes seen in the gut of someone with IBD are caused by the disease itself, or if the changes are what caused disease in the first place, Khoruts said in an email. “Misunderstanding of this critical issue is driving a lot of premature hype about the microbiome.”

Follow NBC HEALTH on Twitter & Facebook.