**PHP擴展安裝**
1\. 環境要求:PHP_VERSION >= 5.3.9,composer工具
2\. 在E盤新建文件夾命名為elastic,,拷貝composer.phar到
? ? ?E:/elastic目錄下面
3\. 打開命令行窗口,進入E:/elastic
4\. 在命令行運行:
? ? ? php composer.phar require elasticsearch/elasticsearch
5\. 此時E:/elastic目錄下會出現一個vendor目錄,安裝成功
6\. 使用方法:
? ? ? ?require 'vendor/autoload.php';?
? ? ? $client = new Elasticsearch\Client();
**創建索引**
1. include('./vendor/autoload.php');??
2. $elastic?=?new?Elasticsearch\Client();??
3. $index[‘index’]?=?‘log’;??//索引名稱??
4. $index[‘type’]?=?‘ems_run_log’;?//類型名稱??
5. $data[‘body’][‘settings’][‘number_of_shards’]?=?5;??//主分片數量??
6. $data[‘body’][‘settings’][‘number_of_replicas’]?=?0;?//從分片數量??
7. $elastic->indices()->create($index);??
**插入索引數據**
1. include('./vendor/autoload.php');??
2. $elastic?=?new?Elasticsearch\Client();??
3. $index[‘index’]?=?‘log’;?//索引名稱??
4. $index[‘type’]?=?‘ems_run_log’;?//類型名稱??
5. $index[‘id’]?=?1???//不指定id,系統會自動生成唯一id??
6. $index[‘body’]?=?array(??
7. ‘mac’?=>?'fcd5d900beca',??
8. ‘customer_id’?=>?3,??
9. ‘product_id’?=>?5,??
10. ‘version’?=>?2??
11. );??
12. $elastic->index($index);??
**查詢**
1. include('./vendor/autoload.php');??
2. $elastic?=?new?Elasticsearch\Client();??
3. $index[‘index’]?=?‘log’;?//索引名稱??
4. $index[‘type’]?=?‘ems_run_log’;?//類型名稱??
5. $index[‘body’][‘query’][‘match’][‘mac’]?=?‘fcd5d900beca’;??
6. $index[‘size’]?=?10;??
7. $index[‘from’]?=?200;??
8. $elastic->search($index);??
相當于sql語句:??
select*from?ems_run_log?where?mac=‘fcd5d900beca’? limit?200,10;
1. include('./vendor/autoload.php');??
2. $elastic?=?new?Elasticsearch\Client();??
3. $index[‘index’]?=?‘log’;?//索引名稱??
4. $index[‘type’]?=?‘ems_run_log’;?//類型名稱??
5. $index[‘body’][‘query’][‘bool’][‘must’]?=?array(??
6. array(‘match’?=>?array(‘mac’?=>?‘fcd5d900beca’)),??
7. array(‘match’?=>?array(‘product_id’?=>?20))??
8. );??
9. $index[‘size’]?=?10;??
10. $index[‘from’]?=?200;??
11. $elastic->search($index);??
相當于sql語句:??
select*from?ems_run_log?where?mac=‘fcd5d900beca’?? and?product_id?=?20?limit?200,10;??
1. include('./vendor/autoload.php');??
2. $elastic?=?new?Elasticsearch\Client();??
3. $index[‘index’]?=?‘log’;?//索引名稱??
4. $index[‘type’]?=?‘ems_run_log’;?//類型名稱??
5. $index[‘body’][‘query’][‘bool’][‘should’]?=?array(??
6. array(‘match’?=>?array(‘mac’?=>?‘fcd5d900beca’)),??
7. array(‘match’?=>?array(‘product_id’?=>?20))??
8. );??
9. $index[‘size’]?=?10;??
10. $index[‘from’]?=?200;??
11. $elastic->search($index);??
當于sql語句:??
select*from?ems_run_log?where?mac=‘fcd5d900beca’?? or?product_id?=?20?limit?200,10;??
1. include('./vendor/autoload.php');??
2. $elastic?=?new?Elasticsearch\Client();??
3. $index[‘index’]?=?‘log’;?//索引名稱??
4. $index[‘type’]?=?‘ems_run_log’;?//類型名稱??
5. $index[‘body’][‘query’][‘bool’][‘must_not’]?=?array(??
6. array(‘match’?=>?array(‘mac’?=>?‘fcd5d900beca’)),??
7. array(‘match’?=>?array(‘product_id’?=>?20))??
8. );??
9. $index[‘size’]?=?10;??
10. $index[‘from’]?=?200;??
11. $elastic->search($index);??
相當于sql語句:??
select*from?ems_run_log?where?mac!=‘fcd5d900beca’? and?product_id?!=?20?limit?200,10;??
1. include('./vendor/autoload.php');??
2. $elastic?=?new?Elasticsearch\Client();??
3. $index[‘index’]?=?‘log’;?//索引名稱??
4. $index[‘type’]?=?‘ems_run_log’;?//類型名稱??
5. $index[‘body’][‘query’][‘range’]?=?array(??
6. ‘id’?=>?array(‘gte’?=>?20,’lt’?=>?30);??
7. );??
8. $index[‘size’]?=?10;??
9. $index[‘from’]?=?200;??
10. $elastic->search($index);??
相當于sql語句:??
select*from?ems_run_log?where?id>=20? and?id<30??limit?200,10;??
**刪除文檔**
1. <pre?name="code"?class="php">include('./vendor/autoload.php');??
2. $elastic?=?new?Elasticsearch\Client();??
3. $index['index']?=?'test';??//索引名稱??
4. $index['type']?=?'ems_test';?//類型名稱??
5. $index['id']?=?2;???
6. $elastic->delete($index);
- 技能知識點
- 對死鎖問題的理解
- 文件系統原理:如何用1分鐘遍歷一個100TB的文件?
- 數據庫原理:為什么PrepareStatement性能更好更安全?
- Java Web程序的運行時環境到底是怎樣的?
- 你真的知道自己要解決的問題是什么嗎?
- 如何解決問題
- 經驗分享
- GIT的HTTP方式免密pull、push
- 使用xhprof對php7程序進行性能分析
- 微信掃碼登錄和使用公眾號方式進行掃碼登錄
- 關于curl跳轉抓取
- Linux 下配置 Git 操作免登錄 ssh 公鑰
- Linux Memcached 安裝
- php7安裝3.4版本的phalcon擴展
- centos7下php7.0.x安裝phalcon框架
- 將字符串按照指定長度分割
- 搜索html源碼中標簽包的純文本
- 更換composer鏡像源為阿里云
- mac 隱藏文件顯示/隱藏
- 谷歌(google)世界各國網址大全
- 實戰文檔
- PHP7安裝intl擴展和linux安裝icu
- linux編譯安裝時常見錯誤解決辦法
- linux刪除文件后不釋放磁盤空間解決方法
- PHP開啟異步多線程執行腳本
- file_exists(): open_basedir restriction in effect. File完美解決方案
- PHP 7.1 安裝 ssh2 擴展,用于PHP進行ssh連接
- php命令行加載的php.ini
- linux文件實時同步
- linux下php的psr.so擴展源碼安裝
- php將字符串中的\n變成真正的換行符?
- PHP7 下安裝 memcache 和 memcached 擴展
- PHP 高級面試題 - 如果沒有 mb 系列函數,如何切割多字節字符串
- PHP設置腳本最大執行時間的三種方法
- 升級Php 7.4帶來的兩個大坑
- 不同域名的iframe下,fckeditor在chrome下的SecurityError,解決辦法~~
- Linux find+rm -rf 執行組合刪除
- 從零搭建Prometheus監控報警系統
- Bug之group_concat默認長度限制
- PHP生成的XML顯示無效的Char值27消息(PHP generated XML shows invalid Char value 27 message)
- XML 解析中,如何排除控制字符
- PHP各種時間獲取
- nginx配置移動自適應跳轉
- 已安裝nginx動態添加模塊
- auto_prepend_file與auto_append_file使用方法
- 利用nginx實現web頁面插入統計代碼
- Nginx中的rewrite指令(break,last,redirect,permanent)
- nginx 中 index try_files location 這三個配置項的作用
- linux安裝git服務器
- PHP 中運用 elasticsearch
- PHP解析Mysql Binlog
- 好用的PHP學習網(持續更新中)
- 一篇寫給準備升級PHP7的小伙伴的文章
- linux 安裝php7 -系統centos7
- Linux 下多php 版本共存安裝
- PHP編譯安裝時常見錯誤解決辦法,php編譯常見錯誤
- nginx upstream模塊--負載均衡
- 如何解決Tomcat服務器打開不了HOST Manager的問題
- PHP的內存泄露問題與垃圾回收
- Redis數據結構 - string字符串
- PHP開發api接口安全驗證
- 服務接口API限流 Rate Limit
- php內核分析---內存管理(一)
- PHP內存泄漏問題解析
- 【代碼片-1】 MongoDB與PHP -- 高級查詢
- 【代碼片-1】 php7 mongoDB 簡單封裝
- php與mysql系統中出現大量數據庫sleep的空連接問題分析
- 解決crond引發大量sendmail、postdrop進程問題
- PHP操作MongoDB GridFS 存儲文件,如圖片文件
- 淺談php安全
- linux上keepalived+nginx實現高可用web負載均衡
- 整理php防注入和XSS攻擊通用過濾