The major averages are far off from their highs, but energy remains a bright spot in the market. Goldman Sachs has identified several buy-rated names it sees as the biggest opportunities for investors. While the S & P 500 is down almost 19% for the year, the energy sector has thrived by comparison, having posted a roughly 40% gain in 2022. As people return to office life, work travel and trip planning through summer and the holidays, demand for oil has rebounded this year. Plus, Russia's war on Ukraine disrupted oil supply this year, leading to a spike in fuel prices. "We recognize that the current near-term macro environment is challenging with growing demand concerns in China, Europe and the U.S. We also recognize the Fed narrative is tough for higher risk ideas such as cyclicals," Goldman's Neil Mehta said in a report Wednesday. "However, stepping back we believe that amid the volatility there will continue to be attractive relative and absolute opportunities that investors can use pullbacks to add to." Here are five small- and mid-cap stocks in oil and gas where Goldman Sachs believes upside outweighs risks: Chesapeake Energy is one of the firm's picks for the exploration and production subsector. Goldman analysts highlighted the company's "underappreciated" inventory depth. The firm said it expects Chesapeake to generate 15% free cash flow yield in 2023 and 10% the following year. Shares have gained 60% this year. Among its refining picks is Delek , which has jumped nearly 80% in 2022. Goldman noted the company has positive momentum around capital returns to shareholders, citing roughly 6% capital returns yield projection for 2023 and room for upside. Weatherford International is Goldman's stock pick for the services subsector. The note said it carries discovery value and added that companies exposed to international oilfield activity will see a stronger rate of change. Further, Weatherford has introduced initiatives to close its margin gap with peers and improve its free cash flow conversion, Goldman says. Shares have risen 14% this year. For oil and global exploration and production, Goldman looked at stocks trading at a discount to their net asset value. That includes Magnolia Oil & Gas , which the firm says is well positioned to generate double-digit free cash flow yield and dividend growth. Its shares are up 16% in 2022. PDC Energy was highlighted in the same subsector. Goldman said its buy rating is driven by the company's ability to acquire well permits in Colorado, de-risk its inventory and ramp up production next year. PDC's shares have jumped about 29% in 2022. — CNBC's Michael Bloom contributed to this report.