Elasticquent\ElasticquentTrait::createIndex PHP Method

createIndex() public static method

Create Index
public static createIndex ( integer $shards = null, integer $replicas = null ) : array
$shards integer
$replicas integer
return array
    public static function createIndex($shards = null, $replicas = null)
    {
        $instance = new static();
        $client = $instance->getElasticSearchClient();
        $index = array('index' => $instance->getIndexName());
        $settings = $instance->getIndexSettings();
        if (!is_null($settings)) {
            $index['body']['settings'] = $settings;
        }
        if (!is_null($shards)) {
            $index['body']['settings']['number_of_shards'] = $shards;
        }
        if (!is_null($replicas)) {
            $index['body']['settings']['number_of_replicas'] = $replicas;
        }
        $mappingProperties = $instance->getMappingProperties();
        if (!is_null($mappingProperties)) {
            $index['body']['mappings'][$instance->getTypeName()] = ['_source' => array('enabled' => true), 'properties' => $mappingProperties];
        }
        return $client->indices()->create($index);
    }