Extracted from stacked PRs #630/#631 (commit 7e64d18). Makes Elasticsearch index creation in tests resilient to a race. Target: `next`.