NEW YORK — Not all record days on the stock market are created equal.

Major U.S. indexes rose to all-time highs for the second day in a row Thursday, but the gains were driven by stocks that investors tend to buy when they want to avoid risk, such as power companies, banks and drug makers.

The flight to less-volatile stocks and those that pay bigger-than-average dividends suggested that investors are becoming more cautious after a 26 percent surge in the market this year. More investors are saying the market has risen too far, too fast given the sluggish economy.

“The legion of people in the last three months who think this market has topped out has grown significantly,” but the general tendency for the market is still to move higher, said JJ Kinahan, chief strategist at TD Ameritrade.