A data-driven optimization strategy based on a generalized pattern search (GPS) algorithm is proposed to automatically optimize piezoelectric energy harvesters (PEHs). As a direct search method, GPS can iteratively solve the derivative-free optimization problem. Taking the finite element method (FEM) as the solver and the GPS algorithm as the optimizer, the automatic interaction between the solver and optimizer ensures optimization with minimum human efforts, saving designers’ time and performing a more precise exploration in the parameter space to obtain better results. When employing it for the optimization of PEHs, the optimal length and thickness of PZT were 6.0 mm and 4.6 µm, respectively. Compared with reported high-output PEHs, this optimal structure showed an increase of 371% in output power, an improvement by 1000% in normalized power density, and a reduction of 254% in resonant frequency. Furthermore, Spearman’s rank correlation coefficient was calculated for evaluating the correlation among geometric parameters and output performance such as resonant frequency and output power, which provides a data-based perspective on the design and optimization of PEHs.