- // PHPの公式APIは無味書かれ、次のクラスES API操作を使用することができます。
- <?phpの
- クラスElasticSearch {
- 公共 $インデックス。
- 関数__construct($サーバー= 'のhttp:// localhostを:9200'){
- の$ this - >サーバー= $サーバ。
- }
- 関数呼び出し($パス、 $ HTTP = 配列()){
- もし(!の$ this - >インデックス) スロー 新しい例外(「の$ this - >インデックスが値を必要とします」);
- リターンjson_decode(のfile_get_contents(の$ this - >サーバー。 '/'。 の$ this - >インデックス。 '/'。 $パス、NULL、stream_context_create(配列('HTTP' => $ HTTP))));
- }
- //カール-XのPUTはhttp:// localhostを:9200 / {INDEX} /
- 関数作成(){
- の$ this - >コール(NULL、 配列('メソッド' => 'PUT'));
- }
- //カール-X HTTPを削除:// localhostを:9200 / {INDEX} /
- 機能低下(){
- の$ this - >コール(NULL、 配列('メソッド' => )'削除')。
- }
- //カール-X GET HTTP:// localhostを:9200 / {INDEX} / _status
- 機能の状態(){
- 返し ます$ this->コール('_statusを');
- }
- //カール-X GET HTTP:// localhostを:9200 / {INDEX} / {TYPE} / _count -d {matchAll:{}}
- 機能の 数($タイプ){
- 戻り の$ this - >コール(。$タイプ '/ _count'、 配列('メソッド' => 'GET'、 => 'コンテンツ' '{matchAll:{}}を'));
- }
- //カール-XのPUTはhttp:// localhostを:9200 / {INDEX} / {TYPE} / _mapping -d ...
- 機能マップ($タイプ、 $データ){
- 戻り の$ this - >コール(。$タイプ '/ _mapping'、 配列('メソッド' => 'PUT'、 'コンテンツ' => $データ))。
- }
- //カール-X PUTのhttp:// localhostを:9200 / {INDEX} / {TYPE} / {ID} -d ...
- 機能追加($型、 $ IDを、 $データ){
- 戻り の$ this - >コール(。$型 。 '/' $ ID、 アレイ('メソッド' => 'PUT'、 'コンテンツ' => $データ))。
- }
- //カール-X GETのhttp:// localhostを:?9200 / {INDEX} / {TYPE} / _search Q = ...
- 機能クエリ($タイプ、 $ qを){
- 返す (の$ this - >コール。$型の '?/ _search'を。http_build_query(配列('Q' => $ Q)));
- }
- }
ます。https://www.cnblogs.com/zhangchenliang/p/4206284.htmlで再現