Origin of the phrase "There, there"

Why, in English, do we say “there, there” when trying to comfort someone? And what precisely does this phrase really mean? Is it an imperative of some weird verbless kind? Are we telling someone to “look over there?” To something that would comfort them? Or is it an abbreviated form of some longer phrase? And if it’s just odd words, why the word “there?” Why not, say, “Green bean, green bean?” Or “Toe, toe?” Or something like that?

According to the Word Detective: