1、安装elasticsearch-2.3.5、javaSE环境
从官网下载最新版,然后用cmd进入解压后的elasticsearch目录,直接用bin/elasticsearch.bat启动。(java环境已经配置好,网上有很多相关教程)。
访问 http://localhost:9200/ (成功后继续进行)
2、下载php环境,用composer 安装 elasticsearch-php
下载好后,将文件夹放入 thinkphp的vendor 下。
3、写thinkphp 的展现类,直接贴我的代码。
<?php
namespace Home\Controller;
use Think\Controller;
use Elasticsearch\ClientBuilder;
class ElasticController extends Controller
{
public function _initialize()
{
Vendor('Elasticsearch.autoload');
$this->client = ClientBuilder::create()->build();
}
public function index()
{
$post = I("get.");
$searchParams['index'] = 'yunnan';
$searchParams['type'] = 'article';