Elasticsearch.php 987 B

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