Plants withstand pathogen attacks by recruiting beneficial bacteria to the rhizosphere and passing their legacy on to the next generation. However, the underlying mechanisms involved in this process remain unclear. In our study, we combined microbiomic and transcriptomic analyses to reveal how the rhizosphere microbiome assembled through multiple generations and defense-related genes expressed in Arabidopsis thaliana under pathogen attack stress. Our results showed that continuous exposure to the pathogen Pseudomonas syringae pv tomato DC3000 led to improved growth and increased disease resistance in a third generation of rps2 mutant Arabidopsis thaliana. It could be attributed to the enrichment of specific rhizosphere bacteria, such as Bacillus and Bacteroides. Pathways associated with plant immunity and growth in A. thaliana, such as MAPK signaling pathways, phytohormone signal transduction, ABC transporter proteins, and flavonoid biosynthesis, were activated under the influence of rhizosphere bacterial communities. Our findings provide a scientific basis for explaining the relationship between beneficial microbes and defense-related gene expression. Understanding microbial communities and the mechanisms involved in plant responses to disease can contribute to better plant management and reduction of pesticide use.