安装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