12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace app\api\controller;
- /**
- * Elasticsearch
- * Class Elasticsearch
- */
- class Es
- {
- public $access_key = 'LTAI5tJ5p12drZegeWVG33xZ';// key
- public $access_secret = '82UWAiY5e5wH8tSkRvMtqVoGO0h8SB';//secret
- public $InstanceId = 'es-cn-wwo34hg5t0006xtsj';
- public $test_index = 'product_info';
- public static function client(){
- $es = \Elasticsearch\ClientBuilder::create()
- ->setHosts(['http://es-cn-wwo34hg5t0006xtsj.public.elasticsearch.aliyuncs.com:9200'])
- ->build();
- // $es = \Elasticsearch\ClientBuilder::create()->build();
- return $es;
- }
- public function es()
- {
- $res = static::client();
- var_dump($res);
- }
- public function createIndex()
- {
- $index = [
- "index"=>"gyx",
- "body"=>[
- "mappings"=>[
- "properties"=>[
- "name"=>[
- "type"=>"keyword"
- ],
- "age"=>[
- "type"=>"byte"
- ],
- "addr"=>[
- "type"=>"text",
- "analyzer"=>"ik_max_word"
- ]
- ]
- ]
- ]
- ];
- $res = static::client()->indices()->create($index);
- var_dump($res);
- }
- }
|