@Override public void afterIndexShardStarted(IndexShard indexShard) { if (indexShard.shardId().index().name().equals(INDEX_NAME)) { // percolator index has started, fetch what we can from it and initialize the indices // we have synchronized (mutex) { if (initialQueriesFetchDone) { return; } // we load the queries for all existing indices for (IndexService indexService : indicesService) { // only load queries for "this" index percolator service if (indexService.index().equals(index())) { loadQueries(indexService.index().name()); } } initialQueriesFetchDone = true; } } if (!indexShard.shardId().index().equals(index())) { // not our index, bail return; } if (!percolatorAllocated()) { return; } // we are only interested when the first shard on this node has been created for an index // when it does, fetch the relevant queries if not fetched already IndexService indexService = indicesService.indexService(indexShard.shardId().index().name()); if (indexService == null) { return; } if (indexService.numberOfShards() != 1) { return; } synchronized (mutex) { if (initialQueriesFetchDone) { return; } // we load queries for this index loadQueries(index.name()); initialQueriesFetchDone = true; } }