Abstract The Rosetta spacecraft observed the temporal evolution of the ion populations within the ionosphere of comet 67P/Churyumov-Gerasimenko. A striking feature of the ion spectrum is represented by the so-called medium-energy ion peaks, which recurrently emerge from the low energy ion background with their energy levels typically reaching 50 to 1000 eV before their energy gradually decreases, and they disappear from the measurements. These peaks are believed to be caused by space weather forcing, but there was no conclusive evidence until now. We investigated the characteristics of these ions, paying special attention to the connection between the solar wind dynamic pressure and the amount and energy of the medium-energy ions. Our findings reveal a strikingly accurate direct correlation between the dynamic pressure of the solar wind at the position of the comet and the amount of medium-energy ions measured by Rosetta. The ion energy also unquestionably reacts to the effects of solar wind pressure variation, but this parameter is strongly affected by the production rate and the distance from the nucleus as well. We explain these close correlations between cometary ion and solar wind characteristics using the well-founded assumption that certain boundary layers of the magnetosphere can move in and out under the influence of higher and lower solar wind pressure.