ElasticSearch 协程客户端 - 删除文档

根据 id 删除文档用法

  1. <?php
  2. $config = new \EasySwoole\ElasticSearch\Config([
  3. 'host' => '127.0.0.1',
  4. 'port' => 9200
  5. ]);
  6. $elasticsearch = new \EasySwoole\ElasticSearch\ElasticSearch($config);
  7. go(function () use ($elasticsearch) {
  8. $bean = new \EasySwoole\ElasticSearch\RequestBean\Delete();
  9. $time = time();
  10. $bean->setIndex('my-index-' . $time);
  11. $bean->setId('my-id-' . $time);
  12. $response = $elasticsearch->client()->delete($bean)->getBody();
  13. $response = json_decode($response, true);
  14. var_dump($response);
  15. });

根据 query 删除文档用法

  1. <?php
  2. $config = new \EasySwoole\ElasticSearch\Config([
  3. 'host' => '127.0.0.1',
  4. 'port' => 9200
  5. ]);
  6. $elasticsearch = new \EasySwoole\ElasticSearch\ElasticSearch($config);
  7. go(function () use ($elasticsearch) {
  8. $bean = new \EasySwoole\ElasticSearch\RequestBean\DeleteByQuery();
  9. $time = time();
  10. $bean->setIndex('my-index-' . $time);
  11. $bean->setBody([
  12. 'query' => [
  13. 'match' => ['name' => '测试删除']
  14. ]
  15. ]);
  16. $response = $elasticsearch->client()->deleteByQuery($bean)->getBody();
  17. $response = json_decode($response, true);
  18. var_dump($response);
  19. });