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命令列客戶端
- ElasticSearch客戶端簡單操作例項Elasticsearch客戶端
- Elasticsearch及java客戶端jest使用ElasticsearchJava客戶端
- php連結nsq客戶端PHP客戶端
- ffrpc的php客戶端libFRPRPCPHP客戶端
- VNC客戶端是Windows,VNC客戶端是Windows如何進行操作VNC客戶端Windows
- php與ethereum客戶端互動PHP客戶端
- ElasticSearch 高階 REST 客戶端翻譯 (待續......)ElasticsearchREST客戶端
- Redis介紹 && Java客戶端操作RedisRedisJava客戶端
- InfluxDB 客戶端基礎操作2UX客戶端
- java客戶端查詢ES操作步驟Java客戶端
- zookeeper在Linux客戶端操作命令大全Linux客戶端
- SSH客戶端常用工具SecureCRT操作客戶端Securecrt
- 使用Java客戶端對Redis進行操作Java客戶端Redis
- Windows下svn客戶端TortoiseSVN的安裝和操作Windows客戶端
- PHP 操作 ElasticSearch7.8.1PHPElasticsearch
- Skywalking PHP客戶端編譯安裝PHP客戶端編譯
- PHP,ASP一句話網馬客戶端PHP客戶端
- 基於Dtm分散式事務管理的php客戶端分散式PHP客戶端
- 《samba搭建win客戶端和linux客戶端的區別》Samba客戶端Linux
- 自己動手寫一個能操作redis的客戶端Redis客戶端
- dubbo客戶端客戶端
- Pulsar客戶端客戶端
- mqtt 客戶端MQQT客戶端
- MQTTJava客戶端的使用MQQTJava客戶端
- redis客戶端的使用Redis客戶端
- IE客戶客戶端程式開發的利器Bindows客戶端
- Nacos - 客戶端心跳續約及客戶端總結客戶端
- 從PHP客戶端看MongoDB通訊協議TDPHP客戶端MongoDB協議
- Linux下php5.3編譯oracle客戶端LinuxPHP編譯Oracle客戶端
- PHP獲取客戶端、PHP獲取伺服器相關資訊PHP客戶端伺服器
- Redis客戶端基本操作以及檢視慢查詢Redis客戶端
- Kubernetes官方java客戶端之七:patch操作Java客戶端
- Linux 平臺安裝SQLServer客戶端操作指南LinuxSQLServer客戶端
- 物理DataGuard客戶端無縫切換--客戶端TAF 配置客戶端
- Python socket的客戶端Python客戶端
- zookeeper的Java客戶端APIJava客戶端API
- Ceph的客戶端安裝客戶端