What can I use to fix a gap between the light fixture and the ceiling?
Wires and connections must be contained in an enclosure that is designed for that purpose. You might be able to find a decorative canopy extension ring at a good lighting and/or fan shop. it might look something like this: