ネイティブAPIを使用した分散型検索エンジンElasticsearch PHPクラスパッケージ

  1. // PHPの公式APIは無味書かれ、次のクラスES API操作を使用することができます。  
  1. <?phpの  
  2.     
  3. クラスElasticSearch {  
  4.   公共  $インデックス。  
  5.    
  6.   関数__construct($サーバー=  'のhttp:// localhostを:9200'){  
  7.     の$ this - >サーバー=  $サーバ。  
  8.   }  
  9.    
  10.   関数呼び出し($パス、  $ HTTP =  配列()){  
  11.     もし(!の$ this - >インデックス)  スロー  新しい例外(「の$ this - >インデックスが値を必要とします」);  
  12.     リターンjson_decode(のfile_get_contents(の$ this - >サーバー。  '/'。  の$ this - >インデックス。  '/'。  $パス、NULL、stream_context_create(配列('HTTP' =>  $ HTTP))));  
  13.   }  
  14.    
  15.   //カール-XのPUTはhttp:// localhostを:9200 / {INDEX} /  
  16.   関数作成(){  
  17.      の$ this - >コール(NULL、  配列('メソッド' =>  'PUT'));  
  18.   }  
  19.    
  20.   //カール-X HTTPを削除:// localhostを:9200 / {INDEX} /  
  21.   機能低下(){  
  22.      の$ this - >コール(NULL、  配列('メソッド' => '削除')。  
  23.   }  
  24.    
  25.   //カール-X GET HTTP:// localhostを:9200 / {INDEX} / _status  
  26.   機能の状態(){  
  27.     返し  ます$ this->コール('_statusを');  
  28.   }  
  29.    
  30.   //カール-X GET HTTP:// localhostを:9200 / {INDEX} / {TYPE} / _count -d {matchAll:{}}  
  31.   機能の  数($タイプ){  
  32.     戻り  の$ this - >コール(。$タイプ  '/ _count'、  配列('メソッド' =>  'GET'、  => 'コンテンツ'  '{matchAll:{}}を'));  
  33.   }  
  34.    
  35.   //カール-XのPUTはhttp:// localhostを:9200 / {INDEX} / {TYPE} / _mapping -d ...  
  36.   機能マップ($タイプ、  $データ){  
  37.     戻り  の$ this - >コール(。$タイプ  '/ _mapping'、  配列('メソッド' =>  'PUT'、  'コンテンツ' =>  $データ))。  
  38.   }  
  39.    
  40.   //カール-X PUTのhttp:// localhostを:9200 / {INDEX} / {TYPE} / {ID} -d ...  
  41.   機能追加($型、  $ IDを、  $データ){  
  42.     戻り  の$ this - >コール(。$型  。 '/'  $ ID、  アレイ('メソッド' =>  'PUT'、  'コンテンツ' =>  $データ))。  
  43.   }  
  44.    
  45.   //カール-X GETのhttp:// localhostを:?9200 / {INDEX} / {TYPE} / _search Q = ...  
  46.   機能クエリ($タイプ、  $ qを){  
  47.     返す  (の$ this - >コール。$型の  '?/ _search'を。http_build_query(配列('Q' =>  $ Q)));  
  48.   }  
  49. }  

ます。https://www.cnblogs.com/zhangchenliang/p/4206284.htmlで再現

おすすめ

転載: blog.csdn.net/weixin_33951761/article/details/93495511