The multi-exit discriminator (MED) helps determine the optimal route for incoming traffic of an AS. It is similar to the metric used in IGP. When a BGP device obtains multiple routes to the same destination address but with different next hops from EBGP peers, the BGP device selects the route with the smallest MED value as the optimal route.
set protocols bgp [vrf <vrf-name>] always-compare-med
MED is one of the parameters that is considered when selecting the best path among many alternative paths. The path with a lower MED is preferred over a path with a higher MED.
During the best-path selection process, MED comparison is done only among paths from the same autonomous system. Use the command bgp always-compare-med to change this behavior by enforcing MED comparison between all paths, regardless of the autonomous system from which the paths are received.
set protocols bgp [vrf <vrf-name>] bestpath med missing-as-worst