Abstract:[Background] Stellaria dichotoma var. lanceolata has an important medicinal value, and its quality can be evaluated based on the total sterols and total flavonoids. [Objective] To explore the endophytic microbial community characteristics in the root of S. dichotoma var. lanceolata growing in different habitats and the relationship of the microbial community structure with the main components and yield of the medicinal herb. [Methods] We employed the high-throughput sequencing and conventional determination methods of medicinal materials to analyze the characteristics of the endophytic microbial community in the roots of S. dichotoma var. lanceolata in different habitats of semi-fixed aeolian sandy soil (SFA), lithosol (LI), and loessal (LO). [Results] The dominant endophytic bacteria were Actinobacteriota and Proteobacteria, and the dominant fungi were Ascomycota and Basidiomycota. The dominant endophytic microbial genera varied depending on the habitats. The content of total sterols and total flavonoids was higher in the LI habitat, while the dry weight per plant and the dry weight-to-fresh weight ratio were higher in the SFA habitat. Spearman correlation analysis suggested that there were rich endophytes represented by metagenome_g__norank_f__67-14 (endophytic bacteria) and unclassified_p__Ascomycota (endophytic fungi) showing significantly positive correlations with the main medicinal components and yield of S. dichotoma var. lanceolata. [Conclusion] The endophytic microbial taxa associating with the key active components of S. dichotoma var. lanceolata have a broad research value in species identification and extraction, strain culture, and secondary metabolite analysis. This study provides a theoretical reference for the development of high-quality medicinal materials in the suitable producing areas of S. dichotoma var. lanceolata.