Elasticsearch.php 954 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\common\service;
  3. use Elastic\Elasticsearch\ClientBuilder;
  4. /**
  5. * Elasticsearch
  6. * Class Elasticsearch
  7. */
  8. class Elasticsearch
  9. {
  10. /**
  11. * @return \Elastic\Elasticsearch\Client
  12. * @throws \Elastic\Elasticsearch\Exception\AuthenticationException
  13. */
  14. public static function es()
  15. {
  16. static $es;
  17. if(!$es) $es= ClientBuilder::create()->build();
  18. return $es;
  19. }
  20. /*
  21. *
  22. */
  23. public static function body()
  24. {
  25. return [
  26. 'mappings'=>[
  27. 'properties'=>[
  28. 'id'=>['type'=>'long'],
  29. 'status'=>['type'=>'byte'],
  30. 'logo'=>['type'=>'text'],
  31. 'name'=>['type'=>'text'],
  32. ]
  33. ]
  34. ];
  35. }
  36. public static function getList($index)
  37. {
  38. $list = static::es()->search([
  39. 'index'=>$index,
  40. ]);
  41. return $list;
  42. }
  43. }