Children who take certain antibiotics called macrolides to treat an infection may experience changes in their gut bacteria, a new study suggests.

And children given more than two courses of macrolides during the first two years of life may face an increased risk of developing asthma and becoming overweight later in childhood, according to the findings.

"In general, it seems that the gut microbiota recovery from antibiotic treatment [takes] more than a year," study author Katri Korpela, of the University of Helsinki, said in a statement. "If a child gets repeated courses of antibiotics during their first years, the microbiota may not have time to fully recover."

Macrolides include azithromycin and erythromycin, and are used for treating lung and chest infections. They are commonly used in people who are allergic to the antibiotic penicillin. [Body Bugs: 5 Surprising Facts About Your Microbiome]

In the study of 142 Finnish children ages 2 to 7, the researchers looked at how many courses of antibiotics the children had received in their lifetimes, and the composition of their gut bacteria. They also studied the children's risk of asthma and obesity.

They found that, among the children who had taken macrolides in the past two years, there were differences in the composition of their gut bacteria, compared with the children who had not taken these antibiotics. These differences had persisted since the children had taken the antibiotics, for as long as two years. And these same changes had been tied to an increased risk of developing obesity and immune-related diseases in previous studies of animals and adult humans, the researchers said.

However, taking penicillin or closely related antibiotics "seemed to have a weaker impact on the composition and functioning of the microbiome than macrolides," Korpela said.

The new findings support the recommendation to avoid using macrolides as the primary antibiotics in children, and restrict the use of all antibiotics to when they are genuinely needed, the researchers said.

Antibiotics should not be used to treat infections that normally resolve on their own and should never be used "just in case," they said.

When it comes to using antibiotics in kids, it is important to find the right balance, said Dr. Punita Ponda, assistant chief in the Division of Allergy and Immunology at Northwell Health in Great Neck, New York, who was not involved in the new study.

Although overusing these medicines, or being too quick to use them, is not good, it is still appropriate to prescribe them if a child really needs them, she said.

"We certainly don't want to go back to the days where people were dying of common infections that could be treated with the antibiotics that we have [now]," Ponda told Live Science. "But you just have to use them judiciously."

The new study was published Jan. 26 in the journal Nature Communications.

Copyright 2016 LiveScience, a TechMediaNetwork company. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.