In Malachi 3 there is a prophecy concerning a messenger which would precede the coming of the Lord.
Malachi 3:1 Behold, I send My messenger, And he will prepare the way before Me. And the Lord, whom you seek, Will suddenly come to His temple, Even the Messenger of the covenant, In whom you delight. Behold, He is coming," Says the LORD of hosts. 2 But who can endure the day of His coming? And who can stand when He appears? For He is like a refiner’s fire And like launderer’s soap. 3 He will sit as a refiner and a purifier of silver; He will purify the sons of Levi, And purge them as gold and silver, That they may offer to the LORD An offering in righteousness.
This was first fulfilled in John Baptist who was sent prior to the beginning of Christ’s ministry.
Matthew 11:10 For this is he of whom it is written: ‘Behold, I send My messenger before your face, who will prepare your way before you.’
The fulfilment was incomplete because Christ will not sit and purify the sons of Levi until his second coming to restore the kingdom of Israel as the kingdom of God. There is a second prophecy in Malachi concerning the sending of Elijah before ‘the great and dreadful day of the LORD’ which is a reference to Christ’s second advent.
Malachi 4:5 Behold, I will send you Elijah the prophet Before the coming of the great and dreadful day of the LORD. 6 And he will turn the hearts of the fathers to the children, And the hearts of the children to their fathers, Lest I come and strike the earth with a curse."
It was and is understood that ‘the great and dreadful day of the LORD’ is the time (still in the future) when the kingdom of God will be established on the earth. Thus, God sent a messenger before Christ’s first advent and this was John Baptist ‘sent in the spirit and power of Elijah’
Luke 1:17 He will also go before Him in the spirit and power of Elijah, ‘to turn the hearts of the fathers to the children,’ and the disobedient to the wisdom of the just, to make ready a people prepared for the Lord.
Before Christ’s second advent God will send Elijah. The Jews and the apostles conflated the two advents not realising that there was to be a gap of some 2000 years between the two. The Jews rejected Jesus because he wasn’t raising an army to break the yoke of the Romans, and they argued with the disciples that Jesus wasn’t the Christ because Elijah hadn’t been sent.
Matthew 17:10 And His disciples asked Him, saying, "Why then do the scribes say that Elijah must come first?" 11 Jesus answered and said to them, "Indeed, Elijah is coming first and will restore all things. 12 "But I say to you that Elijah has come already, and they did not know him but did to him whatever they wished. Likewise the Son of Man is also about to suffer at their hands." 13 Then the disciples understood that He spoke to them of John the Baptist.
From Jesus’ explanation we understand that John Baptist was a ‘type’ of Elijah at Jesus’ first advent, but Elijah himself will be sent to prepare Israel for Jesus’ second advent.
I hope you find this helpful.