在thinkphp中使用elasticsearch

本文介绍了如何通过Composer安装whereof/think-elasticsearch库,并展示了基本的Elasticsearch配置和使用示例。在PHP中,你可以简单地使用Elasticsearch::index()方法来执行索引操作,或者指定连接名执行命令。文章遵循MIT License。
摘要由CSDN通过智能技术生成

安装

composer require whereof/think-elasticsearch

基本配置

ELASTICSEARCH_HOST=localhost
ELASTICSEARCH_PORT=9200
ELASTICSEARCH_SCHEME=http
ELASTICSEARCH_USER=
ELASTICSEARCH_PASS=

常规使用

$data = [ 'body' => [ 'testField' => 'abc' ], 'index' => 'my_index', 'type' => 'my_type', 'id' => 'my_id', ];

$client = ClientBuilder::create()->build(); $return = $client->index($data);

您现在可以简单地替换最后两行:

$return = Elasticsearch::index($data);

这将在默认连接上运行命令。 你可以运行一个命令 任何连接(参见 defaultConnection 设置和 connections 数组 配置文件)。

$return = Elasticsearch::connection('connectionName')->index($data);

Copyright and License

MIT License.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值