Background: Primary insomnia (PI) refers to syndromes of difficulty falling asleep, poor sleep quality, early awakening, and difficulty falling asleep after waking up. Although there have been numerous studies, the specific etiology and pathogenesis of PI are still misunderstanding. In recent years, the gut microbiota has been proved to be involved in the metabolism of many mental disorders. But the specific mechanisms of its involvement in PI have not been fully elucidated. This study aims to explore the relationship between the gut microbiota and the symptoms, cognitive function changes in PI. Methods: In this study, the gut microbiota of PI patients and healthy controls was profiled by performing stool 16s rRNA gene sequencing. The co-occurrence network was constructed by using Weight Gene Co-expression Network Analysis (WGCNA) algorithm. The correlation between gut microbiota associated pathways and traits in PI were predicted. Results: WGCNA results demonstrated several Operational Taxonomic Units (OTU) modules are correlated to symptoms. By using PICRUSt2 software, we predicted the Kyoto Encyclopedia of Genes and Genomes (KEGG) pathways of microbiota in modules. For instance, sleep efficiency may be correlated with the presence of Insulin signaling pathway, Flavonoid biosynthesis, Ascorbate and aldarate metabolism, Nitrotoluene degradation, Biotin metabolism, RNA polymerase and Chlorocyclohexane and chlorobenzene degradation. Total sleep time may be correlated with the presence of Tyrosine metabolism, Propanoate metabolism, Carbon fixation pathways in prokaryotes, Carotenoid biosynthesis, Systemic lupus erythematosus, Nitrotoluene degradation and Biosynthesis of unsaturated fatty acids. The severity of insomnia may be correlated with Insulin signaling pathway, Flavonoid biosynthesis, Ascorbate and aldarate metabolism, Nitrotoluene degradation, Biotin metabolism and RNA polymerase. Change of name score in Montreal Cognitive Assessment (MoCA) may be correlated with Tyrosine metabolism, Propanoate metabolism, Carbon fixation pathways in prokaryotes, Carotenoid biosynthesis, Systemic lupus erythematosus, Nitrotoluene degradation, Biosynthesis of unsaturated fatty acids, Apoptosis, Steroid hormone biosynthesis, Geraniol degradation, Protein digestion and absorption and Bisphenol degradation in Gut Microbiota (GM). Conclusion: This study revealed the potential relationships between gut microbiota and PI. By using pathway prediction and enrichment analysis, we concluded many metabolic pathways may associated with some important traits of insomnia patients, including sleep efficiency, severe insomnia, total sleep time and change of name score in MoCA. The metabolic pathways include Insulin signaling pathway, Flavonoid biosynthesis, Ascorbate and aldarate metabolism, Nitrotoluene degradation, Biotin metabolism, RNA polymerase and Chlorocyclohexane, chlorobenzene degradation, Tyrosine metabolism, Propanoate metabolism, Carbon fixation pathways in prokaryotes, Carotenoid biosynthesis, Systemic lupus erythematosus, Biosynthesis of unsaturated fatty acids, Apoptosis, Steroid hormone biosynthesis, Geraniol degradation, Protein digestion and absorption and Bisphenol degradation.Our study demonstrated that PI patients demonstrate significant changes in gut microbiota, which will help delineate the relationship between gut microbiota and syndromes of PI.