The Earth is nestled inside a constantly changing magnetic field which fluctuates in result of inner core processes. Coincidentally this magnetic field protects the surface from high levels of radiation emanating from the sun, thus contributing to the unique conditions supporting life on the planet. Paleomagnetists understand Earth's magnetic field swaps poles (or reversals) roughly every hundred thousand years by evidence discovered in rock layers throughout the world. These alterations to ancient rocks eerily prove the ability of a strong magnetic field and its influence on physical matter. This evidence is how geologists are aware of Earth's polar shift phases every 50,000 years like clockwork.
It took until middle ages for creditable documents to surface with an applicable understanding of magnetism by aiding ship navigation with a compass. Before then, written documents about electricity and magnetism are few and far between, but it's apparent our ancestors had a basic understanding by artifacts discovered from ancient Olmec and Chinese cultures. There's also an intriguing device discovered in Mesopotamia dating to a short period between 200-600 BCE called the Bagdad Battery, seemingly designed to extract an electric charge from chemical reactions using acidic solutions.
† Article 6-41