Doctors typically recommend gastroscopy when patients exhibit symptoms that may indicate gastrointestinal cancer, such as difficulty swallowing, persistent stomach pain, unexplained weight loss, vomiting blood, or chronic acid reflux. It is also used for patients with a family history of gastrointestinal cancers or those who have Helicobacter pylori infection, which is a risk factor for stomach cancer.