Parallelly Index for same entity for IT testing

Test cases are working fine with below configuration and before every test clear index data and recreate it.
The problem here is if I run test cases more than one place it start failing as indexes are clear because of “before method” and index data is inconsistent .


import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


  • Configuration for Hibernate Search. This class defines the format of indexes being created in elastic server.

  • @author Abhishek Swarnkar

  • @version 1.0

  • @since 25-09-2020
    public class CustomLayoutStrategy implements IndexLayoutStrategy {

    private static final DateTimeFormatter INDEX_SUFFIX_FORMATTER =
    DateTimeFormatter.ofPattern(“uuuuMMdd-HHmmss-SSSSSSSSS”, Locale.ROOT)
    private static final Pattern UNIQUE_KEY_PATTERN =

    public String createInitialElasticsearchIndexName(String hibernateSearchIndexName) {
    return hibernateSearchIndexName + “-”

    public String createWriteAlias(String hibernateSearchIndexName) {
    return hibernateSearchIndexName + “-write”;

    public String createReadAlias(String hibernateSearchIndexName) {
    return hibernateSearchIndexName;

    public String extractUniqueKeyFromHibernateSearchIndexName(
    String hibernateSearchIndexName) {
    return hibernateSearchIndexName;

    public String extractUniqueKeyFromElasticsearchIndexName(
    String elasticsearchIndexName) {
    Matcher matcher = UNIQUE_KEY_PATTERN.matcher(elasticsearchIndexName);
    if (!matcher.matches()) {
    throw new IllegalArgumentException(
    "Unrecognized index name: " + elasticsearchIndexName

public void before() throws Exception {
SearchSession searchSession =;

Closed with help of How to know if index already exist in elastic server