S
S
Snewer2016-10-31 21:13:03
Yii
Snewer, 2016-10-31 21:13:03

Why is data not being added to Elasticsearch?

Hello!
There is an ActiveRecord Elasticsearch model:

<?php

namespace app\models;

use \yii\elasticsearch\ActiveRecord;

class Test extends ActiveRecord {

    function attributes()
    {
        return ['message', 'timestamp'];
    }

    function rules()
    {
        return [
            [$this->attributes(), 'safe']
        ];
    }

}

Next, in the test controller, I insert an entry:
$q = new \app\models\Test();
$q->attributes = [
    'message' => 'Сообщение',
    'timestamp' => time(),
];
// $q->primaryKey = 1;
$q->save();

if primaryKey is not specified, then the record is not inserted:
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
        )

)

what is the reason? ES version 5.0.0

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Puma Thailand, 2016-11-01
@opium

1 indicate the primer cay
2 do the same with your hands

V
vito8877, 2017-02-22
@vito8877

Just Yii2 so far (02/22/2017) only supports elasticsearch up to version 4.x (5 versions are not supported)
https://github.com/yiisoft/yii2-elasticsearch

This extension works with elasticsearch version 1.0 to 4.x. elasticsearch 5.0 is currently not supported.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question