After a tough 2022, the first half of this year was like a breath of fresh air for investors. Stocks climbed, with eight of 11 industries contributing to the rally. The S&P 500 Index rose more than 15%. And the index even advanced more than 20% from its bear market low.

But one particular industry didn't join this exciting party. And that's the healthcare sector. While high-growth sectors like technology and consumer discretionary pushed indexes higher, healthcare put the brakes on gains. As we head into the second half of the year, should you buy stocks in this beaten-down sector -- or go for the first-half winners instead? Let's find out.

Why healthcare stumbled

First, let's talk about why healthcare stocks stumbled recently. I don't see the movement as a reflection of the quality of healthcare companies or their long-term prospects. Instead, it's part of a general movement toward stocks that may excel in a bull market.

We're not in a bull market yet, but one is coming. And investors want to be prepared. So, they've favored growth stocks, known to outperform in times of market strength. (You'll find growth stocks in the healthcare industry -- for example, telemedicine leader Teladoc or robotic surgery company Intuitive Surgical.) But, generally, when investors think growth, technology is one of the first sectors to come to mind. And technology contributed the most to the S&P 500's gains in the first half, according to Statista.

This chart shows contributions to the stock market rally by industry.

Source: Statista.

Why are investors expecting a bull market? These times of market growth always follow bear markets. So, we know one will arrive sooner or later. And improvements in some companies' earnings and resilience in certain economic reports have helped buoy sentiment. All of this resulted in a shift out of the safety of healthcare and into higher-growth areas -- from technology stocks to cryptocurrency.

Now, let's get back to our question: Should we snap up stocks in healthcare right now? It's true that, when the new bull market arrives, healthcare probably won't be the sector to lead gains. But that isn't a reason to ignore these stocks.

Here's why. To give yourself the very best chance of investment success, it's important to invest over the long term. This means your investment horizon will be much longer than the next bull or bear market. So, right now, it's key to look at a company's valuation and future prospects. And due to declines in the first half of the year, you may find some very good bargains in healthcare.

Two top players to buy now

For example, Pfizer (PFE 0.55%) has dropped 30% since the start of the year, leaving it trading at only 10 times forward earnings estimates. Some investors have worried about declines in coronavirus vaccine sales and Pfizer's upcoming losses of exclusivity for major drugs. But the pharma giant also plans to launch 19 new drugs within 18 months. These drugs and recent acquisitions should more than compensate for patent losses in the coming years, according to Pfizer's calculations. All of this makes Pfizer a top long-term stock to buy now.

Johnson & Johnson (JNJ -0.46%) is another big pharma company that's slipped this year. Today, it's trading for only 15 times forward earnings estimates. This is a steal considering J&J's dividend growth as a Dividend King -- and the new wave of revenue growth that may be just ahead. J&J is spinning off its slowest-growing business -- consumer health -- to favor the higher-growth businesses of pharma and medtech.

Of course, this doesn't mean you should avoid growth stocks and the first-half's biggest winners. It's fine to go for a few stocks that might lead the bull market higher -- only if those stocks have solid long-term prospects too.

So, right now, instead of going after only the stocks that may excel in a bull market, go for stocks that have what it takes to rise over time. And, in healthcare, you'll find plenty of great opportunities.