Thank you for the kind explanations.
I modified the query as below, and it worked quickly and correctly:
match (m) where elementId(m) in $nodes
with collect(m) as nodes
CALL apoc.path.expandConfig(nodes[0], {
labelFilter: "-DataCenter|-Version|-Type",
endNodes: [nodes[1]],
minLevel: 2,
uniqueness: "RELATIONSHIP_PATH"
}) YIELD path
RETURN path LIMIT 1
If the query takes long time for you to run, adding an index on the name property will make it fast.