我們目前正在我們的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);
}
當我保存模型時,它會自動將它添加到ES,但是當我更新它時,它不會更新模型。當我回應時,它不會拋出任何錯誤。
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) }
我在做什麼錯在這裏?
的'_version'正確遞增每次更新,現在看來,這意味着更新工作。運行'curl -XGET localhost:9200/testindex/user/20604'時會得到什麼? – Val
相同,不正確的輸出。 '{ 「_index」: 「testindex」, 「_類型」: 「用戶」, 「_ ID」: 「20604」, 「_版本」:4 「找到」:真, 「_源」:{ 「ID」: 「20604」 ,「name」:「test person」,「email」:「[email protected]」,「test」:「」}}' –
如果你運行我從你的shell給你的curl,你應該簡單地獲取文檔ID爲'20604',請分享。 – Val