一、安装ElasticSearch6.4.0
1.Elastic 需要 Java 8 环境
2.Download Elasticsearch
我用的是Version:6.4.0==>去官网下载
3.到\elasticsearch-6.4.0\bin双击启动elasticsearch.bat
4.安装成功
二、安装ElasticSearch的Head插件
推荐博客,亲测有效
1.安装nodejs
C:\Users\qinmt>node -v
v8.3.0
2.安装Git
3.安装grunt
grunt构建工具,可以进行打包压缩、测试、执行等等的工作,head插件就是通过grunt启动的。因此需要安装grunt:
注意:路径切到E:\nodejs下。
//cmd切到nodejs目录下执行
#npm install -g grunt-cli
4.安装grunt
把head插件的源码git clone下来:
//执行
#git clone git://github.com/mobz/elasticsearch-head.git
5.在head源码目录中,执行npm install
6.在head源代码目录下启动服务
//执行
#grunt server
7.安装成功
8.访问http://localhost:9100就可以看到head插件了
三、通过Composer包管理工具直接下载Elasticsearch-PHP
推荐博客,亲测有效,但是一定要注意版本的问题!!!
1.去下载Composer
1. Composer中文网==>去下载
2. 提供另外一个通道去下载Composer-Setup.exe 链接:https://pan.baidu.com/s/10FnljFDUn7t1X-yMGhAcuA 密码:t242
2.安装Composer时候一定要选择php-7.0!!!
3.在服务器根目录下创建一个elasticphp文件夹,在该文件夹中创建一个composer.json文件,内容如下:
{
"require": {
"elasticsearch/elasticsearch": "6.0",
}
}
4.cmd进入到elasticphp目录下
#composer update
5.初始化成功,并在elasticphp目录下创建一个index.php文件
require 'vendor/autoload.php'; //加载自动加载文件
#如果没有设置主机地址默认为127.0.0.1:9200
$client = Elasticsearch\ClientBuilder::create()->setHosts(['localhost:9200'])->build();
var_dump($client);
6.去创建一个索引
$params = [
'index' => 'create_index',
'body' => [
'settings' => [
'number_of_shards' => 2,
'number_of_replicas' => 0
]
]
];
$response = $client->indices()->create($params);
print_r($response);
die;
7.访问http://localhost:9100/看执行结果
更多例子去看官方教程