PHP 中运用 elasticsearch
来源:互联网 发布:奥卡福体测数据 编辑:程序博客网 时间:2024/06/06 13:13
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();
创建索引
include('./vendor/autoload.php'); $elastic = new Elasticsearch\Client(); $index[‘index’] = ‘log’; //索引名称 $index[‘type’] = ‘ems_run_log’; //类型名称 $data[‘body’][‘settings’][‘number_of_shards’] = 5; //主分片数量 $data[‘body’][‘settings’][‘number_of_replicas’] = 0; //从分片数量 $elastic->indices()->create($index);
include('./vendor/autoload.php'); $elastic = new Elasticsearch\Client(); $index[‘index’] = ‘log’; //索引名称 $index[‘type’] = ‘ems_run_log’; //类型名称 $index[‘id’] = 1 //不指定id,系统会自动生成唯一id $index[‘body’] = array( ‘mac’ => 'fcd5d900beca', ‘customer_id’ => 3, ‘product_id’ => 5, ‘version’ => 2 ); $elastic->index($index);
查询
include('./vendor/autoload.php'); $elastic = new Elasticsearch\Client(); $index[‘index’] = ‘log’; //索引名称 $index[‘type’] = ‘ems_run_log’; //类型名称 $index[‘body’][‘query’][‘match’][‘mac’] = ‘fcd5d900beca’; $index[‘size’] = 10; $index[‘from’] = 200; $elastic->search($index); 相当于sql语句: select*from ems_run_log where mac=‘fcd5d900beca’ limit 200,10;<strong></strong>
include('./vendor/autoload.php'); $elastic = new Elasticsearch\Client(); $index[‘index’] = ‘log’; //索引名称 $index[‘type’] = ‘ems_run_log’; //类型名称 $index[‘body’][‘query’][‘bool’][‘must’] = array( array(‘match’ => array(‘mac’ => ‘fcd5d900beca’)), array(‘match’ => array(‘product_id’ => 20)) ); $index[‘size’] = 10; $index[‘from’] = 200; $elastic->search($index); 相当于sql语句: select*from ems_run_log where mac=‘fcd5d900beca’ and product_id = 20 limit 200,10;
include('./vendor/autoload.php'); $elastic = new Elasticsearch\Client(); $index[‘index’] = ‘log’; //索引名称 $index[‘type’] = ‘ems_run_log’; //类型名称 $index[‘body’][‘query’][‘bool’][‘should’] = array( array(‘match’ => array(‘mac’ => ‘fcd5d900beca’)), array(‘match’ => array(‘product_id’ => 20)) ); $index[‘size’] = 10; $index[‘from’] = 200; $elastic->search($index); 相当于sql语句: select*from ems_run_log where mac=‘fcd5d900beca’ or product_id = 20 limit 200,10;
include('./vendor/autoload.php'); $elastic = new Elasticsearch\Client(); $index[‘index’] = ‘log’; //索引名称 $index[‘type’] = ‘ems_run_log’; //类型名称 $index[‘body’][‘query’][‘bool’][‘must_not’] = array( array(‘match’ => array(‘mac’ => ‘fcd5d900beca’)), array(‘match’ => array(‘product_id’ => 20)) ); $index[‘size’] = 10; $index[‘from’] = 200; $elastic->search($index); 相当于sql语句: select*from ems_run_log where mac!=‘fcd5d900beca’ and product_id != 20 limit 200,10;
include('./vendor/autoload.php'); $elastic = new Elasticsearch\Client(); $index[‘index’] = ‘log’; //索引名称 $index[‘type’] = ‘ems_run_log’; //类型名称 $index[‘body’][‘query’][‘range’] = array( ‘id’ => array(‘gte’ => 20,’lt’ => 30); ); $index[‘size’] = 10; $index[‘from’] = 200; $elastic->search($index); 相当于sql语句: select*from ems_run_log where id>=20 and id<30 limit 200,10;
<pre name="code" class="php">include('./vendor/autoload.php');$elastic = new Elasticsearch\Client();$index['index'] = 'test'; //索引名称$index['type'] = 'ems_test'; //类型名称$index['id'] = 2; $elastic->delete($index);
0 0
- PHP 中运用 elasticsearch
- php中运用elasticsearch(composer)
- php运用elasticsearch
- PHP中运用正则表达式
- php中set_time_limit()函数运用
- 7.php中MongoDB的运用。
- 在PHP中 运用LINUX命令
- PHP中如何运用ini_set和ini_get()
- PHP中如何运用ini_set和ini_get()
- PHP中goto语法的运用
- 怎样在PHP 中运用 SimpleXML 处理任务
- PHP 中运用Smarty 实现HTML静态化
- php中运用http调用的GET和POST方法
- 关于PHP中key和current,next的联合运用
- php中运用http调用的GET和POST方法
- CTF中遇见的PHP伪协议运用
- PHP ElasticSearch的使用
- Elasticsearch-PHP 概述
- (转)主成分分析(Principal components analysis)-最大方差解释及
- Xcode 6 关于 iOS App 国际化问题
- HDOJ 排序(用5分隔)
- Online Judge System For SzNOI 题库 语法百题 c++ d018
- hession开发遇到的问题 Server returned HTTP response code: 500 for URL:
- PHP 中运用 elasticsearch
- 在 python 使用socket 获取 IP
- STL map常用操作简介
- spring List,Set,Map,Properties,array的使用配置文件注入实例
- c#调用硬件提供的二次开发函数方法
- C++ primer读书笔记 4
- 2012年5月SAT香港真题解析
- 使用NTFS文件系统加密文件后,重装系统,文件打不开
- list_borrow_view.setEmptyView(empty_view); 当listview为空则显示这个