Background: A non-endoscopic capsule-sponge device allows sampling the entire length of the esophagus. Here, we compared microbiomes of the oral cavity, esophagus, and gastric corpus collected by oral swab, capsule-sponge device, and endoscopic biopsy, respectively, in patients representing three distinct risk profiles for esophageal squamous cell carcinoma (ESCC). Methods: The study enrolled 11 patients with esophageal squamous intraepithelial neoplasia, 21 patients after curative treatment for head and neck squamous cell cancer (HNSCC) (HNSCC survivors), and 40 patients with functional dyspeptic (FD) symptoms. Microbial genomic DNA was analyzed using 16S rRNA gene amplicon sequencing. Results: The Shannon index of the capsule-sponge sample microbiota was significantly higher in FD group than in patients after treatment for HNSCC, and the Chao index of gastric samples differed between HNSCC survivors and FD patients. Analysis of the β-diversity of FD patients, HNSCC, and esophageal squamous intraepithelial neoplasia showed that different genera formed at each location. The abundance of 205, 116, and 9 genera differed between FD patients and HNSCC survivors in the gastric, capsule-sponge, and oral samples, respectively; 33 genera differed between the FD group and patients with esophageal squamous intraepithelial neoplasia in capsule-sponge samples. Conclusions: The bacterial communities of the upper digestive tract were clustered according to the anatomic site. Despite substantial differences in gastric and esophageal microbiota samples between FD patients and HNSCC survivors, the microbial members and diversity showed small differences between FD patients and those with esophageal squamous intraepithelial neoplasia. It remains unclear whether gastric and esophageal dysbiosis is associated with or is a consequence of treatment for HNSCC.