core/src/main/java/org/elasticsearch/indices/IndicesService.java
public synchronized IndexService createIndex(final NodeServicesProvider nodeServicesProvider, IndexMetaData indexMetaData, List<IndexEventListener> builtInListeners) throws IOException {
        if (!lifecycle.started()) {
            throw new IllegalStateException("Can't create an index [" + indexMetaData.getIndex() + "], node is closed");
        }
        final Index index = indexMetaData.getIndex();
        final Predicate<String> indexNameMatcher = (indexExpression) -> indexNameExpressionResolver.matchesIndex(index.getName(), indexExpression, clusterService.state());
        final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, indexNameMatcher, indexScopeSetting);
        if (indices.containsKey(index.getName())) {
            throw new IndexAlreadyExistsException(index);
        }
        logger.debug("creating Index [{}], shards [{}]/[{}{}]",
                indexMetaData.getIndex(),
                idxSettings.getNumberOfShards(),
                idxSettings.getNumberOfReplicas(),
                idxSettings.isShadowReplicaIndex() ? "s" : "");

        final IndexModule indexModule = new IndexModule(idxSettings, indexStoreConfig, analysisRegistry);
        pluginsService.onIndexModule(indexModule);
        for (IndexEventListener listener : builtInListeners) {
            indexModule.addIndexEventListener(listener);
        }
        indexModule.addIndexEventListener(oldShardsStats);
        final IndexEventListener listener = indexModule.freeze();
        listener.beforeIndexCreated(index, idxSettings.getSettings());
        final IndexService indexService = indexModule.newIndexService(nodeEnv, this, nodeServicesProvider, mapperRegistry, indicesFieldDataCache, indexingMemoryController);
        boolean success = false;
        try {
            assert indexService.getIndexEventListener() == listener;
            listener.afterIndexCreated(indexService);
            indices = newMapBuilder(indices).put(index.getName(), indexService).immutableMap();
            success = true;
            return indexService;
        } finally {
            if (success == false) {
                indexService.close("plugins_failed", true);
            }
        }

    }
/**
     * Creates a new {@link IndexService} for the given metadata.
     * @param indexMetaData the index metadata to create the index for
     * @param builtInListeners a list of built-in lifecycle {@link IndexEventListener} that should should be used along side with the per-index listeners
     * @throws IndexAlreadyExistsException if the index already exists.
     */
Creates a new  IndexService for the given metadata.
@param indexMetaData the index metadata to create the index for
@param builtInListeners a list of built-in lifecycle  IndexEventListener that should should be used along side with the per-index listeners
@throws IndexAlreadyExistsException if the index already exists.
Creates a new IndexService for the given metadata . @param indexMetaData the index metadata to create the index for @param builtInListeners a list of built - in lifecycle IndexEventListener that should should be used along side with the per - index listeners @throws IndexAlreadyExistsException if the index already exists .
public synchronized IndexService createIndex(final NodeServicesProvider nodeServicesProvider, IndexMetaData indexMetaData, List<IndexEventListener> builtInListeners) throws IOException {
        if (!lifecycle.started()) {
            throw new IllegalStateException("Can't create an index [" + indexMetaData.getIndex() + "], node is closed");
        }
        final Index index = indexMetaData.getIndex();
        final Predicate<String> indexNameMatcher = (indexExpression) -> indexNameExpressionResolver.matchesIndex(index.getName(), indexExpression, clusterService.state());
        final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, indexNameMatcher, indexScopeSetting);
        if (indices.containsKey(index.getName())) {
            throw new IndexAlreadyExistsException(index);
        }
        logger.debug("creating Index [{}], shards [{}]/[{}{}]",
                indexMetaData.getIndex(),
                idxSettings.getNumberOfShards(),
                idxSettings.getNumberOfReplicas(),
                idxSettings.isShadowReplicaIndex() ? "s" : "");
        final IndexModule indexModule = new IndexModule(idxSettings, indexStoreConfig, analysisRegistry);
        pluginsService.onIndexModule(indexModule);
        for (IndexEventListener listener : builtInListeners) {
            indexModule.addIndexEventListener(listener);
        }
        indexModule.addIndexEventListener(oldShardsStats);
        final IndexEventListener listener = indexModule.freeze();
        listener.beforeIndexCreated(index, idxSettings.getSettings());
        final IndexService indexService = indexModule.newIndexService(nodeEnv, this, nodeServicesProvider, mapperRegistry, indicesFieldDataCache, indexingMemoryController);
        boolean success = false;
        try {
            assert indexService.getIndexEventListener() == listener;
            listener.afterIndexCreated(indexService);
            indices = newMapBuilder(indices).put(index.getName(), indexService).immutableMap();
            success = true;
            return indexService;
        } finally {
            if (success == false) {
                indexService.close("plugins_failed", true);
            }
        }
    }
public synchronized IndexService createIndex ( final NodeServicesProvider nodeServicesProvider , IndexMetaData indexMetaData , List < IndexEventListener > builtInListeners ) throws IOException { if ( ! lifecycle . started ( ) ) { throw new IllegalStateException ( "Can't create an index [" + indexMetaData . getIndex ( ) + "], node is closed" ) ; } final Index index = indexMetaData . getIndex ( ) ; final Predicate < String > indexNameMatcher = ( indexExpression ) -> indexNameExpressionResolver . matchesIndex ( index . getName ( ) , indexExpression , clusterService . state ( ) ) ; final IndexSettings idxSettings = new IndexSettings ( indexMetaData , this . settings , indexNameMatcher , indexScopeSetting ) ; if ( indices . containsKey ( index . getName ( ) ) ) { throw new IndexAlreadyExistsException ( index ) ; } logger . debug ( "creating Index [{}], shards [{}]/[{}{}]" , indexMetaData . getIndex ( ) , idxSettings . getNumberOfShards ( ) , idxSettings . getNumberOfReplicas ( ) , idxSettings . isShadowReplicaIndex ( ) ? "s" : "" ) ; final IndexModule indexModule = new IndexModule ( idxSettings , indexStoreConfig , analysisRegistry ) ; pluginsService . onIndexModule ( indexModule ) ; for ( IndexEventListener listener : builtInListeners ) { indexModule . addIndexEventListener ( listener ) ; } indexModule . addIndexEventListener ( oldShardsStats ) ; final IndexEventListener listener = indexModule . freeze ( ) ; listener . beforeIndexCreated ( index , idxSettings . getSettings ( ) ) ; final IndexService indexService = indexModule . newIndexService ( nodeEnv , this , nodeServicesProvider , mapperRegistry , indicesFieldDataCache , indexingMemoryController ) ; boolean success = false ; try { assert indexService . getIndexEventListener ( ) == listener ; listener . afterIndexCreated ( indexService ) ; indices = newMapBuilder ( indices ) . put ( index . getName ( ) , indexService ) . immutableMap ( ) ; success = true ; return indexService ; } finally { if ( success == false ) { indexService . close ( "plugins_failed" , true ) ; } } }
Creates a new {@link IndexService} for the given metadata.
Creates a new { @link IndexService } for the given metadata .