Closes elastic/elasticsearch#303 Original commit: elastic/x-pack-elasticsearch@84b535a68c
Original commit: elastic/x-pack-elasticsearch@15caf307c4