2016-07-25 7 views
1

現在、WebappでElasticSearchを実装中です。公式elasticsearch-php frameworkを使用してこれを行います。私たちはこれを新しいモデルにしたので、これをモデルに直接実装してテストしました。ElasticSearchが更新されていません

public function afterSave() 
{ 
    $client = \Elasticsearch\ClientBuilder::create()->build(); 
    $params = [ 
     'index' => 'testindex', 
     'type' => 'user', 
     'id' => $this->id, 
     'body' => [ 
      'id' => $this->id, 
      'name' => $this->firstname.' '.$this->lastname, 
      'email' => $this->email, 
      'test' => '' 
     ] 
    ]; 

    $response = $client->index($params); 
} 

public function afterUpdate() 
{ 
    $client  = \Elasticsearch\ClientBuilder::create()->build(); 
    $params  = [ 
     'index' => 'testindex', 
     'type' => 'user', 
     'id' => $this->id 
    ]; 

    $params['body']['doc'] = [ 
     'test' => 'test2' 
    ]; 

    $response = $client->update($params); 
    var_dump($client->update($params)); 
    var_dump($response); 
} 

モデルを保存すると自動的にモデルに追加されますが、モデルを更新してもモデルは更新されません。私がvar_dump()の応答を返すと、エラーは発生しません。

array(4) { ["index"]=> string(11) "testindex" ["type"]=> string(5) "user" ["id"]=> string(5) "20604" ["body"]=> array(1) { ["doc"]=> array(1) { ["test"]=> string(5) "test2" } } } 

array(4) { ["_index"]=> string(11) "testindex" ["_type"]=> string(5) "user" ["_id"]=> string(5) "20604" ["_version"]=> int(2) } 

array(4) { ["_index"]=> string(11) "testindex" ["_type"]=> string(5) "user" ["_id"]=> string(5) "20604" ["_version"]=> int(3) } 

私はここで間違っていますか?

+0

、更新が働いていたことを意味する、と思われます。 'curl -XGET localhost:9200/testindex/user/20604'を実行するとどうなりますか? – Val

+0

同じ、間違った出力。 "_index": "testindex"、 "_ type": "user"、 "_ id": "20604"、 "_ version":4、 "found":true、 "_ source":{"id": "20604" "name": "test person"、 "email": "[email protected]"、 "test": ""}} ' –

+0

あなたがシェルから与えたカールを実行すると、 id '20604'で、それを共有してください。 – Val

答えて

0

Phalconを使用している場合、update()afterUpdate()afterSave()の両方を呼び出している可能性があります。 afterSave()メソッドには、echoの数を配置する必要があります。あなたがそれらを2度見たら、これが問題です。

afterSave()ハンドルの更新とafterCreate()ハンドルの作成によってこの現象を防ぐことができます。その後、$model->create()を呼び出してモデルを作成し、$model->save()を呼び出してモデルを更新することができます。

もっとこの動作に関する情報はで見つけることができます: `_version`が正しく更新ごとにインクリメントされhttps://docs.phalconphp.com/en/latest/reference/models.html#create-update-with-confidence

関連する問題