ElasticSearch 协程客户端 - 删除文档
根据 id 删除文档用法
<?php
$config = new \EasySwoole\ElasticSearch\Config([
'host' => '127.0.0.1',
'port' => 9200
]);
$elasticsearch = new \EasySwoole\ElasticSearch\ElasticSearch($config);
go(function () use ($elasticsearch) {
$bean = new \EasySwoole\ElasticSearch\RequestBean\Delete();
$time = time();
$bean->setIndex('my-index-' . $time);
$bean->setId('my-id-' . $time);
$response = $elasticsearch->client()->delete($bean)->getBody();
$response = json_decode($response, true);
var_dump($response);
});
根据 query 删除文档用法
<?php
$config = new \EasySwoole\ElasticSearch\Config([
'host' => '127.0.0.1',
'port' => 9200
]);
$elasticsearch = new \EasySwoole\ElasticSearch\ElasticSearch($config);
go(function () use ($elasticsearch) {
$bean = new \EasySwoole\ElasticSearch\RequestBean\DeleteByQuery();
$time = time();
$bean->setIndex('my-index-' . $time);
$bean->setBody([
'query' => [
'match' => ['name' => '测试删除']
]
]);
$response = $elasticsearch->client()->deleteByQuery($bean)->getBody();
$response = json_decode($response, true);
var_dump($response);
});
当前内容版权归 EasySwoole 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 EasySwoole .