One scholar explains that
"The Hebrew word, 'Messiah' is rendered in Geek as "Christ", and both
words mean 'anointed'... In the ancient world, as today in our own
country [Britain], kings were anointed with oil at their coronation.
Messiah and Christos both mean God's Anointed King." The Daily Study Bible, The Gospel of John, vol. 1, William Barclay, p.88 The Saint
Andrew Press, 1982
As to how Andrew knew Jesus to be this anointed one, he and another disciple of John the Baptist heard John denying being the Christ (John 1:25) when asked by some Pharisees. Andrew and that other disciple had been baptised by the Baptist, in preparation for the one to come - the Messiah. They were following the Baptist, learning from him, prior to this event.
The day after John denied being the Christ, he had gone on to identify Jesus as the Spirit-anointed Son of God (vs. 34). The day following that, Andrew and the other disciple saw John identify the man passing by as Jesus, The Lamb of God (vs. 35). That was enough for them to then follow after Jesus, (about 16:00 hours) and to spend the rest of the day with him. And that was enough for Andrew to then find his brother to tell him, "We have found the Messiah".
We are not told what Andrew and the other disciple learned from Jesus as they spent time with him. Whatever it was, that (combined with the Baptist's testimony) served to convince Andrew that Jesus was the long-expected Messiah. And the day after he said, "We have found the Messiah", confirmation of that truth was shown when Nathaniel's experience caused him to declare that Jesus was "the Son of God, the King of Israel" (vs.s. 43-49).
It took three years of being disciples of Jesus for all of them to finally come to grips with the significance of Jesus being the Messiah. Many misconceptions had to be abandoned, and it was the resurrection that really let the light of the Messiah flood in to them.
Andrew knew from the Hebrew scriptures why John the Baptist had denied being the Messiah, pointing instead to Jesus. John was the fulfillment of the prophecy in Malachi 3:1. The previously quoted scholar goes on to explain about verses 35-39:
"Once again we see John the Baptist pointing beyond himself. He must
have known very well that to speak to his disciples about Jesus like
that was to invite them to leave him and transfer their loyalty to
this new and greater teacher; and yet he did it. There was no jealousy
in John. He had come to attach men not to himself but to Christ. There
is no harder task than to take the second place when once the first
place was enjoyed. But as soon as Jesus emerged on the scene John never
had any other thought than to send men to him." (Ibid. p.85)
Being well prepared by John to receive the Messiah when he appeared, Andrew and the other disciple never hesitated. They believed Jesus to be the Messiah, God's anointed King.