Elasticsearch的PHP客戶端操作
叢集設定 $hosts = [ '127.0.0.1:9200' ]; $client = ElasticsearchClientBuilder::create()->setHosts($hosts)->build(); //建立文件 $params = [ 'index' => 'my_index', 'type' => 'my_type', 'id' => 'my_id', 'body' => ['testField' => 'abc'] ]; $response = $client->index($params); //獲取文件 $params = [ 'index' => 'my_index', 'type' => 'my_type', 'id' => 'my_id' ]; $response = $client->get($params); //查詢文件 $params = [ 'index' => 'my_index', 'type' => 'my_type', 'body' => [ 'query' => [ 'match' => [ 'testField' => 'abc' ] ] ] ]; $response = $client->search($params); //刪除文件 $params = [ 'index' => 'my_index', 'type' => 'my_type', 'id' => 'my_id' ]; $response = $client->delete($params); //刪除索引 $deleteParams = [ 'index' => 'my_index' ]; $response = $client->indices()->delete($deleteParams); //建立索引 $params = [ 'index' => 'my_index', 'body' => [ 'settings' => [ 'number_of_shards' => 2, 'number_of_replicas' => 0 ] ] ]; $response = $client->indices()->create($params); //忽略異常 $params = [ 'index' => 'test_missing', 'type' => 'test', 'id' => 1, 'client' => [ 'ignore' => [400, 404] ] ]; $response = $client->get($params); //獲取響應詳細資訊 $params = [ 'index' => 'my_index', 'type' => 'my_type', 'id' => 1, 'client' => [ 'verbose' => true, 'ignore' => [400, 404] ] ]; $response = $client->get($params); //啟用未來模式 $params = [ 'index' => 'my_index', 'type' => 'my_type', 'id' => 'my_id', 'client' => [ 'future' => 'lazy' ] ]; $future = $client->get($params); $response = $future->wait(); //空物件 $params = [ 'index' => 'megacorp', 'type' => 'employee', 'body' => [ 'query' => [ 'match_phrase' => [ 'about' => 'rock climbing' ] ], 'highlight' => [ 'fields' => [ ['about' => new stdClass()] ] ] ] ]; $response = $client->search($params); $params = [ 'index' => 'my_index', 'body' => [ 'mappings' => [ 'my_type' => [ "include_in_all" => false, 'properties' => [ 'name' => [ 'type' => 'string', 'analyzer' => 'ik' ], 'price_now' => [ 'type' => 'double', 'index' => 'not_analyzed' ], 'image_thumb' => [ 'type' => 'string', 'index' => 'not_analyzed' ], 'sales_total' => [ 'type' => 'integer', 'index' => 'not_analyzed' ], 'comment' => [ 'type' => 'integer', 'index' => 'not_analyzed' ], 'create_date' => [ 'type' => 'string', 'index' => 'not_analyzed' ], 'status' => [ 'type' => 'byte', 'index' => 'no' ], 'sale' => [ 'type' => 'byte', 'index' => 'no' ] ] ] ] ] ]; $response = $client->indices()->create($params); print_r($response);
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/854/viewspace-2801512/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ElasticSearch-命令列客戶端操作Elasticsearch命令列客戶端
- 搜尋引擎ElasticSearch18_ElasticSearch的客戶端操作2Elasticsearch客戶端
- ElasticSearch客戶端簡單操作例項Elasticsearch客戶端
- php連結nsq客戶端PHP客戶端
- php與ethereum客戶端互動PHP客戶端
- VNC客戶端是Windows,VNC客戶端是Windows如何進行操作VNC客戶端Windows
- InfluxDB 客戶端基礎操作2UX客戶端
- Skywalking PHP客戶端編譯安裝PHP客戶端編譯
- ElasticSearch 高階 REST 客戶端翻譯 (待續......)ElasticsearchREST客戶端
- php: 操作elasticsearch的別名PHPElasticsearch
- zookeeper在Linux客戶端操作命令大全Linux客戶端
- PHP 操作 ElasticSearch7.8.1PHPElasticsearch
- SSH客戶端常用工具SecureCRT操作客戶端Securecrt
- java客戶端查詢ES操作步驟Java客戶端
- Kubernetes官方java客戶端之七:patch操作Java客戶端
- 基於Dtm分散式事務管理的php客戶端分散式PHP客戶端
- 自己動手寫一個能操作redis的客戶端Redis客戶端
- 客戶端登陸logout操作,事務回滾客戶端Go
- Kubernetes官方java客戶端之五:proto基本操作Java客戶端
- Kubernetes官方java客戶端之六:OpenAPI基本操作Java客戶端API
- Python socket的客戶端Python客戶端
- 從PHP客戶端看MongoDB通訊協議TDPHP客戶端MongoDB協議
- dubbo客戶端客戶端
- Pulsar客戶端客戶端
- mqtt 客戶端MQQT客戶端
- Redis客戶端基本操作以及檢視慢查詢Redis客戶端
- 服務端,客戶端服務端客戶端
- 客戶端,服務端客戶端服務端
- Nacos - 客戶端心跳續約及客戶端總結客戶端
- php原生socket實現客戶端與服務端資料傳輸PHP客戶端服務端
- 物理DataGuard客戶端無縫切換--客戶端TAF 配置客戶端
- [Redis 客戶端整合] Java 中常用Redis客戶端比較Redis客戶端Java
- zookeeper的Java客戶端APIJava客戶端API
- java websocket 客戶端JavaWeb客戶端
- redis客戶端管理Redis客戶端
- iscsi linux客戶端Linux客戶端
- Zookeeper 客戶端 API客戶端API
- 客戶端加解密客戶端解密