implements query by key