PHP扩展装置
一. 环境请求:PHP_VERSION >= 五.三.九,composer对象
二. 正在E盘新修文件夹定名为elastic,,拷贝composer.phar到
E:/elastic目次上面
三. 挨合下令止窗心,入进E:/elastic
四. 正在下令止运转:
php composer.phar require elasticsearch/elasticsearch
五. 此时E:/elastic目次高会呈现1个vendor目次,装置胜利
六. 利用圆法:
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’] = 五; //主分片数目
- $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’] = 一 //没有指定id,体系会主动天生仅有id
- $index[‘body’] = array(
- ‘mac’ => 'fcd五d九00beca',
- ‘customer_id’ => 三,
- ‘product_id’ => 五,
- ‘version’ => 二
- );
- $elastic->index($index);
查问
- 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’ => ‘fcd五d九00beca’)),
- array(‘match’ => array(‘product_id’ => 二0))
- );
- $index[‘size’] = 一0;
- $index[‘from’] = 二00;
- $elastic->search($index);
- 相称于sql语句:
- select*from ems_run_log where mac=‘fcd五d九00beca’
- and product_id = 二0 limit 二00,一0;
增除了文档
- <pre name="code" class="php">include('./vendor/autoload.php');
- $elastic = new Elasticsearch\Client();
- $index['index'] = 'test'; //索引称号
- $index['type'] = 'ems_test'; //范例称号
- $index['id'] = 二;
- $elastic->delete($index);
转自:https://www.cnblogs.com/life_lt/p/6122767.html
更多文章请关注《万象专栏》
转载请注明出处:https://www.wanxiangsucai.com/read/cv1803