安裝composer:非root啟動
~~~
[root@centos6 es]# cat /home/esu/.composer/config.json
{
"config": {},
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
}
}
}
[root@centos6 es]#
~~~
composer安裝es
~~~
[root@centos6 es]# cat composer.json
{
"require": {
"elasticsearch/elasticsearch": "~6.0"
}
}
[root@centos6 es]#
~~~
su esu
~~~
bash-4.1$ composer install --no-dev
Loading composer repositories with package information
Updating dependencies
Package operations: 5 installs, 0 updates, 0 removals
- Installing psr/log (1.0.2): Downloading (100%)
- Installing react/promise (v2.5.1): Downloading (100%)
- Installing guzzlehttp/streams (3.0.0): Downloading (100%)
- Installing guzzlehttp/ringphp (1.1.0): Downloading (100%)
- Installing elasticsearch/elasticsearch (v6.0.1): Downloading (100%)
Writing lock file
Generating autoload files
bash-4.1$
~~~
~~~
[root@centos6 es]# cat test.php
<?php
require_once('vendor/autoload.php');
use Elasticsearch\ClientBuilder;
function create_index(){
//Elastic search php client
$client = Elasticsearch\ClientBuilder::create()->build();
$mysql_conf = array(
'host' => '127.0.0.1:3306',
'db' => 'es',
'db_user' => 'root',
'db_pwd' => '000000',
);
$mysqli = @new mysqli($mysql_conf['host'], $mysql_conf['db_user'], $mysql_conf['db_pwd']);
if ($mysqli->connect_errno) {
die("could not connect to the database:\n" . $mysqli->connect_error);//診斷連接錯誤
}
$mysqli->query("set names 'utf8';");//編碼轉化
$select_db = $mysqli->select_db($mysql_conf['db']);
if (!$select_db) {
die("could not connect to the db:\n" . $mysqli->error);
}$sql = "select * from emp";
$res = $mysqli->query($sql);
if (!$res) {
die("sql error:\n" . $mysqli->error);
}
while ($row = $res->fetch_assoc()) {
$rtn[] = $row;
}
//delete index which already created
$params = array();
$params['index'] = 'emp_index';
$client->indices()->delete($params);
//create index on log_date,src_ip,dest_ip
$rtnCount = count($rtn);
for($i=0;$i<$rtnCount;$i++){
$params = array();
$params['body'] = array(
'id' => $rtn[$i]['id'],
'fdName' => $rtn[$i]['fdName'],
'fdAge' => $rtn[$i]['fdAge'],
'fdStatus' => $rtn[$i]['fdStatus']
);
$params['index'] = 'emp_index';
$params['type'] = 'emp_type';
//Document will be indexed to log_index/log_type/autogenerate_id
$client->index($params);
}
echo 'create index done!';
}
function search(){
//Elastic search php client
$client = Elasticsearch\ClientBuilder::create()->build();
$params = array();
$params['index'] = 'emp_index';
$params['type'] = 'emp_type';
$params['body']['query']['match']['fdStatus'] = '1';
// $params['body']['sort'] = array('fdStatus'=>array('order'=>'asc'));
$params['size'] = 3;
$params['from'] = 1;
$rtn = $client->search($params);
var_dump($rtn);
}
set_time_limit(0);
//create_index();
search();
?>
~~~
**疑問:Fielddata is disabled on text field???**
- 關于我
- laravel
- quickstart
- quickstart-intermediate
- swoole
- (一)快速起步
- php7
- swoole異步高性能
- 開發中常見問題
- event擴展的安裝
- phptrace
- 用C/C++寫php擴展
- 無聊的筆試題
- rewrite二級目錄轉二級域名
- php多進程
- rpc-yar
- php專家列表
- php守護進程
- php函數防止超時
- php分析報錯信息
- gdb調試php
- php-cli模式
- composer/pear
- 基礎
- sublime+xdebug
- 開啟opcache
- 前端
- js
- linux
- Xshell連接不上Ubuntu解決方式
- xshell
- centos安裝中文輸入
- centos下安裝谷歌瀏覽器
- centos安裝phpstorm
- php7之phpredis安裝
- 磁盤大小
- dns
- TCP/IP協議
- HTTP
- tcpdump
- zbacktrace
- gdb調試php擴展
- lsof
- perf
- lnmp
- first
- 重定向
- echo
- 鍵盤高效操作
- 權限控制
- 進程
- 環境變量
- vi
- 軟件包管理
- 網絡
- 查找文件
- 壓縮
- 正則
- sed/awk
- 編譯程序
- shell腳本
- shell認識
- sh腳本
- sh調試相關
- win共享文件夾給虛擬機
- git
- git的安裝
- 常用命令
- 本地到遠程倉庫
- 遠程到本地倉庫
- 分支管理
- bug分支
- feature
- 標簽
- 多人協作
- FAQ
- C/C++
- 難點
- 修飾符
- 數組
- 字符串
- 指針
- 引用
- 面向對象
- 類訪問修飾符
- 構造函數
- 操作文件
- mysql集群
- 使用navicat操作MySQL數據庫能不能整個數據庫搜索一條數據?
- 幫助的使用
- 存儲引擎的選擇
- 數據類型/字符集
- 索引
- kafka集群
- rabbitmq集群
- (一)初識rabbitmq
- (二)原理
- (三)消息模型
- (四)rabbitmq&php基礎
- (五)持久化&route&指定exchange
- (六)發布訂閱
- (七)route key
- (八)topic
- elasticsearch集群
- (一)服務端搭建
- (二)elasticsearch&php
- (三)head插件
- redis集群
- github
- 設計模式
- createType
- factory_method.php
- abstract_factory.php
- mysql_singleton.php
- builder.php
- prototype.php
- structType
- adapter.php
- 數據結構與算法
- python