Здравствуйте!
Имеется ActiveRecord Elasticsearch модель:
<?php
namespace app\models;
use \yii\elasticsearch\ActiveRecord;
class Test extends ActiveRecord {
function attributes()
{
return ['message', 'timestamp'];
}
function rules()
{
return [
[$this->attributes(), 'safe']
];
}
}
Далее в тестовом контроллере вставляю запись:
$q = new \app\models\Test();
$q->attributes = [
'message' => 'Сообщение',
'timestamp' => time(),
];
// $q->primaryKey = 1;
$q->save();
если не указывать primaryKey, то запись не вставляется:
Elasticsearch Database Exception – yii\elasticsearch\Exception
Elasticsearch request failed with code 400.
Error Info: Array
(
[requestMethod] => POST
[requestUrl] => http://127.0.0.1:9200/tests/test?op_type=create
[requestBody] => {"message":"Сообщение","timestamp":1477937279}
[responseCode] => 400
[responseHeaders] => Array
(
[content-type] => application/json; charset=UTF-8
[content-length] => 311
)
[responseBody] => Array
(
[error] => Array
(
[root_cause] => Array
(
[0] => Array
(
[type] => action_request_validation_exception
[reason] => Validation Failed: 1: an id must be provided if version type or value are set;
)
)
[type] => action_request_validation_exception
[reason] => Validation Failed: 1: an id must be provided if version type or value are set;
)
[status] => 400
)
)
в чем причина? версия ES 5.0.0