安装elasticsearch-php,在php上使用,Elasticsearch,以及安装Elasticsearch-php

在php上使用须要安装Elasticsearch-phpphp

安装需求:html

PHP 7.0.0或更高版本.json

须要安装: Composer.app

ext-curl : PHP的Libcurl扩展 (我也不知道是啥php的一个扩展)composer

反正我没安装过 Libcurl 是可替代的...不知道.curl

原生 JSON 扩展 (ext-json) 1.3.7或更高版本(也没安装过).elasticsearch

Elasticsearch-php的版本须要和Elasticsearch版本适配(这个本身百度,安装6.0应该就能够了)ui

好了能够上面都是废话能够来安装了url

在你的composer.json文件中增长这个spa

{

"require": {

"elasticsearch/elasticsearch": "~6.0"

}

}

而后执行php composer.phar update

基础配置   文件 config/app.php

// 地址端口   //这个必须配置正确否则无法用

'elasticsearch_host'          => ['127.0.0.1:9200'],

(一下默认配置便可)

//分片

'number_of_shards'            => 2,

//副本,若是只有一台机器,设置为0

'number_of_replicas'          => 0,

// 开启便可,不然某些功能不可用

'enabled'                     => 'true',

(这个如今只有一个索引不须要配置,之后可能须要)

// 索引名

'params_index'                => 'zb_log',

//type

'params_mappings'             => 'tp_log',

基础使用

实例化

$Elas = new \app\common\controller\Elasticsearch();

会自动建立索引 与索引字段

索引字段:

name  日志名称

content 日志内容

addtime 建立时间

添加日志操做

$Elas ->addSingleElastics($name, $content)

参数:

$name  =  日志名称

$content  =  日志内容

返回数据:自动生成的id (暂时没啥用)

日志查询操做

$res = $Elas->getElastice(true);

参数:  默认false

说明:  该方法不传参数则视为不分页 传true 分页

返回数据:  与tp方法:select()、paginate() 返回同样、

id该id是自动生成的id只在删除时须要

查询条件方法  只能添加一个查询条件

$Elas->WhereElastice($where);

参数:

$where  =  [ 索引字段  =>  值 ]

说明: 在须要条件查询的时候 在查询方法(getElastice)前调用便可

删除某条日志

$res = $Elas->delElastice($id);

参数:

$id 添加时自动生成的id  查询时会返回出来

返回数据: 成功true 、失败false

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值