The earliest is likely Gilgamesh and Enkidu as told in the Sumerian standalone poem Gilgamesh, Enkidu, and the Nether World:
Warrior Gilgamec, son of Ninsumun, directed his steps on his own to E-kur, the temple of Enlil. He cried before Enlil: "Father Enlil, my ellag fell down into the nether world, my ekidma fell down into Ganzer. Enkidu went down to retrieve them but the nether world has seized him. Namtar did not seize him, the Asag did not seize him; but the nether world has seized him. The udug demon of Nergal, who spares nobody, did not seize him, but the nether world has seized him. He did not fall in battle on the field of manhood, but the nether world has seized him." Father Enlil did not stand by him in the matter, so he went to Eridug.
[230-237] In Eridug he directed his steps on his own to the temple of Enki. He cried before Enki: "Father Enki, my ellag fell down into the nether world, my ekidma fell down into Ganzer. Enkidu went down to retrieve them but the nether world has seized him. Namtar did not seize him, the Asag did not seize him; but the nether world has seized him. The udug demon of Nergal, who spares nobody, did not seize him, but the nether world has seized him. He did not fall in battle on the field of manhood, but the nether world has seized him." Father Enki stood by him in this matter.
[238-242] He said to the young warrior Utu, the son born by Ningal: "Open a hole in the nether world immediately, and then bring up his servant from the nether world!" He opened a hole in the nether world and brought up his servant with his breeze (?) from the nether world.
[243-253] They hugged and kissed. They wearied each other with questions: "Did you see the order of the nether world? -- If only you would tell me, my friend, if only you would tell me!" "If I tell you the order of the nether world, sit down and weep! I shall sit down and weep! ......, which your heart rejoiced to touch, is ......, worms infest it like an old garment (?); like ...... of (?) a crevice, it is full of dust." "Alas!" he said and sat down in the dust..
This likely dates to the Ur III period (ca. 2100-2000 BCE), and is the earliest I can think of.
Two others are fairly early, all things considered. The first is from the Bible. In II Sam. 28, Saul, the king of the Israelites, talks to Samuel's ghost:
Then Saul told his officers, “Find me a woman who can talk to the spirits of the dead. I’ll go to her and find out what’s going to happen.”
His servants told him, “There’s a woman at Endor who can talk to spirits of the dead.”
8 That night, Saul put on different clothing so nobody would recognize him. Then he and two of his men went to the woman, and asked, “Will you bring up the ghost of someone for us?”
9 The woman said, “Why are you trying to trick me and get me killed? You know King Saul has gotten rid of everyone who talks to the spirits of the dead!”
10 Saul replied, “I swear by the living Lord that nothing will happen to you because of this.”
11 “Who do you want me to bring up?” she asked.
“Bring up the ghost of Samuel,” he answered.
12 When the woman saw Samuel, she screamed. Then she turned to Saul and said, “You’ve tricked me! You’re the king!”
13 “Don’t be afraid,” Saul replied. “Just tell me what you see.”
She answered, “I see a spirit rising up out of the ground.”
14 “What does it look like?”
“It looks like an old man wearing a robe.”
Saul knew it was Samuel, so he bowed down low.
15 “Why are you bothering me by bringing me up like this?” Samuel asked.
“I’m terribly worried,” Saul answered. “The Philistines are about to attack me. God has turned his back on me and won’t answer any more by prophets or by dreams. What should I do?”
Samuel is usually dated between 600 and 550.
Another early example of this is in Aeschylus' Persae. There, Darius is raised from the dead by Atossa, his wife, because his son, Xerxes, is failing miserably at conquering the Greeks:
Lord of Persia's lord, appear:
Thus involved with thrilling cries
Come, our tale of sorrow hear!
War her Stygian pennons spreads,
Brooding darkness o'er our heads;
For stretch'd along the dreary shore
The flow'r of Asia lies distain'd with gore.
Rise, Darius, awful power;
Long for thee our tears shall flow.
Why thy ruin'd empire o'er
Swells this double flood of wo?
Sweeping o'er the azure tide
Rode thy navy's gallant pride:
Navy now no more, for all
Beneath the whelming wave-
While the CHORUS Sings, ATOSSA performs her ritual by the tomb. As the song concludes the GHOST OF DARIUS appears from the tomb.
GHOST OF DARIUS
Ye faithful Persians, honour'd now in age,
Once the companions of my youth, what ills
Afflict the state? The firm earth groans, it opes,
Disclosing its vast deeps; and near my tomb
I see my wife: this shakes my troubled soul
With fearful apprehensions; yet her off'rings
Pleased I receive. And you around my tomb
Chanting the lofty strain, whose solemn air
Draws forth the dead, with grief-attemper'd notes
Mournfully call me: not with ease the way
Leads to this upper air; and the stern gods,
Prompt to admit, yield not a passage back
But with reluctance: much with them my power
Availing, with no tardy step I come.
Say then, with what new ill doth Persia groan?
The Persae premiered in 472 BCE, so not that long after Samuel.