我们目前正在我们的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