Es.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\api\controller;
  3. /**
  4. * Elasticsearch
  5. * Class Elasticsearch
  6. */
  7. class Es
  8. {
  9. public $access_key = 'LTAI5tJ5p12drZegeWVG33xZ';// key
  10. public $access_secret = '82UWAiY5e5wH8tSkRvMtqVoGO0h8SB';//secret
  11. public $InstanceId = 'es-cn-wwo34hg5t0006xtsj';
  12. public $test_index = 'product_info';
  13. public static function client(){
  14. // $es = \Elasticsearch\ClientBuilder::create()->setHosts(['101.132.128.55:9200'])->build();
  15. $es = \Elasticsearch\ClientBuilder::create()->build();
  16. return $es;
  17. }
  18. public function es()
  19. {
  20. $res = static::client();
  21. var_dump($res);
  22. }
  23. public function createIndex()
  24. {
  25. $index = [
  26. "index"=>"gyx",
  27. "body"=>[
  28. "mappings"=>[
  29. "properties"=>[
  30. "name"=>[
  31. "type"=>"keyword"
  32. ],
  33. "age"=>[
  34. "type"=>"byte"
  35. ],
  36. "addr"=>[
  37. "type"=>"text",
  38. "analyzer"=>"ik_max_word"
  39. ]
  40. ]
  41. ]
  42. ]
  43. ];
  44. $res = static::client()->indices()->create($index);
  45. var_dump($res);
  46. }
  47. }