1 安装composer
curl -sS https://getcomposer.org/installer | php
php composer.phar
2 修改根目录的composer.json
在require 增加一行
增加 "require":{"elasticsearch/elasticsearch":"~6.0"}
3 cd 到根目录 然后执行
composer update elasticsearch/elasticsearch
4 thinkPHP使用
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->setHosts(['127.0.0.1:9200'])->build();
$query = [
'query' => [
'match' => [ 'title_tag_geshi' => $keywords .$geshi],
]
];
$params = [
'index' => 'taotu',
// 'index' => 'm*', #index 和 type 是可以模糊匹配的,甚至这两个参数都是可选的
'type' => 'page',
'body' => array_merge([ 'from' => 0, 'size' => 300],$query)
];
$data = $client->search($params);