Upper endoscopy is a procedure in which the gastroenterologist uses a thin flexible tube, inserted with a camera and a light to look directly into the esophagus(food pipe), stomach and upper small intestine. This test is used to help figure out why kids have stomach pain, diarrhea, throwing up, or constipation( trouble going). Small tissue samples that are the size of a pinhead may be taken by your doctor.