Closes elastic/elasticsearch#328 Original commit: elastic/x-pack-elasticsearch@04235e714a
Original commit: elastic/x-pack-elasticsearch@15caf307c4