Fix reference code query and ES field, fixes #6695