- <?php
-
- class ElasticSearch {
- public $index;
-
- function __construct($server = 'http://localhost:9200'){
- $this->server = $server;
- }
-
- function call($path, $http = array()){
- if (!$this->index) throw new Exception('$this->index needs a value');
- return json_decode(file_get_contents($this->server . '/' . $this->index . '/' . $path, NULL, stream_context_create(array('http' => $http))));
- }
-
-
- function create(){
- $this->call(NULL, array('method' => 'PUT'));
- }
-
-
- function drop(){
- $this->call(NULL, array('method' => 'DELETE'));
- }
-
-
- function status(){
- return $this->call('_status');
- }
-
-
- function count($type){
- return $this->call($type . '/_count', array('method' => 'GET', 'content' => '{ matchAll:{} }'));
- }
-
-
- function map($type, $data){
- return $this->call($type . '/_mapping', array('method' => 'PUT', 'content' => $data));
- }
-
-
- function add($type, $id, $data){
- return $this->call($type . '/' . $id, array('method' => 'PUT', 'content' => $data));
- }
-
-
- function query($type, $q){
- return $this->call($type . '/_search?' . http_build_query(array('q' => $q)));
- }
- }
-
相关文章:
-
2021-11-07
-
2022-01-23
-
2021-09-03
-
2022-12-23
-
2023-03-23
-
2021-11-09
-
2022-12-23
猜你喜欢
-
2022-01-30
-
2021-12-05
-
2021-11-09
-
2021-11-12
-
2021-08-26
-
2022-01-29
相关资源
-
下载
2022-12-09
-
下载
2021-06-06
-
下载
2023-02-20