增删改查

最后更新于:2022-04-02 04:01:55

[TOC] > [官方手册](https://www.elastic.co/guide/cn/elasticsearch/php/current/_configuration.html) ## 添加 mappings ``` $params = [ 'index' => 'my_index', 'body' => [ 'settings' => [ 'number_of_shards' => 3, 'number_of_replicas' => 2 ], 'mappings' => [ 'my_type' => [ '_source' => [ 'enabled' => true ], 'properties' => [ 'first_name' => [ 'type' => 'keyword', ], 'age' => [ 'type' => 'integer' ] ] ] ] ] ]; // Create the index with mappings and settings now $response = $client->indices()->create($params); ``` ## 增 ### 添加 index/type ``` $params =[ 'index' => 'video3', 'type'=>'video', 'id' => '222', 'body'=>[ 'name'=>"1212", 'age'=>11, ] ]; $response = $client->index($params); ``` ## 查 ### 搜索全部信息 ``` $params = [ 'index' => 'video2', 'type' => 'video', ]; $response = $client->search($params); ``` ### 忽略 404 ``` $client = ClientBuilder::create()->build(); $params = [ 'index' => 'test_missing', 'type' => 'test', 'id' => 1, 'client' => [ 'ignore' => 404 ] ]; echo $client->get($params); > {"_index":"test_missing","_type":"test","_id":"1","found":false} ``` ### 删除 ``` $params =[ 'index' => 'video3', 'type'=>'video', 'id' => '222', ]; $response = $client->delete($params); ```
';