When adding record to elasticsearch one-by-one using the following code it works:
$elastic = new Elastic();
$elastic->name = 'Jhon Doe';
$elastic->email = 'johndoe@email.com';
if ($elastic->insert()) {
echo "Added Successfully";
} else {
echo "Error";
}
But when I tried to index complete table using the following code it is not work
$elastic = Elastic::createIndex();
if (isset($elastic)) {
echo "Index created Successfully";
} else {
echo "Error";
}
This is the createIndex() method inside Elastic model
public static function createIndex(){
$db = static::getDb();
$command = $db->createCommand();
$command->createIndex(static::index(), ['mappings' => static::mapping()]);
}
Please tell me how can I index complete table using elastic search in yii2. My table has three fields ‘id’, ‘name’ and ‘email’. I’m using yii2-elasticsearch extension.