The endoscopy procedure has demonstrated great efficiency in detecting stomach lesions, with extensive numbers of endoscope images produced globally each day. The content-based gastric image retrieval (CBGIR) system has demonstrated substantial potential in gastric image analysis. Gastric precancerous diseases (GPD) have higher prevalence in gastric cancer patients. Thus, effective intervention is crucial at the GPD stage. In this paper, a CBGIR method is proposed using a modified ResNet-18 to generate binary hash codes for a rapid and accurate image retrieval process. We tested several popular models (AlexNet, VGGNet and ResNet), with ResNet-18 determined as the optimum option. Our proposed method was valued using a GPD data set, resulting in a classification accuracy of 96.21 ± 0.66% and a mean average precision of 0.927 ± 0.006, outperforming other state-of-art conventional methods. Furthermore, we constructed a Gastric-Map (GM) based on feature representations in order to visualize the retrieval results. This work has great auxiliary significance for endoscopists in terms of understanding the typical GPD characteristics and improving aided diagnosis.