For the reliable fabrication of the current and next generation of nanostructures it is essential to be able to determine their material composition and dimensional parameters. Using the grazing incidence X-ray fluoresence technique, which is taking advantage of the X-ray standing wave field effect, nanostructures can be investigated with a high sensitivity with respect to the structural and elemental composition. This is demonstrated using lamellar gratings made of Si$_3$N$_4$. Rigorous field simulations obtained from a Maxwell solver based on the finite element method allow to determine the spatial distribution of elemental species and the geometrical shape with sub-nm resolution. The increasing complexity of nanostructures and demanded sensitivity for small changes quickly turn the curse of dimensionality for numerical simulation into a problem which can no longer be solved rationally even with massive parallelisation. New optimization schemes, e.g. machine learning, are required to satisfy the metrological requirements. We present reconstruction results obtained with a Bayesian optimization approach to reduce the computational effort.