Es.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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()
  15. ->setHosts(['http://es-cn-wwo34hg5t0006xtsj.public.elasticsearch.aliyuncs.com:9200'])
  16. ->build();
  17. // $es = \Elasticsearch\ClientBuilder::create()->build();
  18. return $es;
  19. }
  20. public function es()
  21. {
  22. $res = static::client();
  23. var_dump($res);
  24. }
  25. public function createIndex()
  26. {
  27. $index = [
  28. "index"=>"gyx",
  29. "body"=>[
  30. "mappings"=>[
  31. "properties"=>[
  32. "name"=>[
  33. "type"=>"keyword"
  34. ],
  35. "age"=>[
  36. "type"=>"byte"
  37. ],
  38. "addr"=>[
  39. "type"=>"text",
  40. "analyzer"=>"ik_max_word"
  41. ]
  42. ]
  43. ]
  44. ]
  45. ];
  46. $res = static::client()->indices()->create($index);
  47. var_dump($res);
  48. }
  49. }