Win10 安装elasticsearch & java环境

Win10 安装elasticsearch & 安装java环境 & wamp环境下的elastic配置

1) 先安装composer 从 https://getcomposer.org/download 下载 找到wamp环境的php.exe 一路下一步完成。
2)java环境 从 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 下载 jdk-8u121-windows-x64.exe 
考虑到后续更新我没有放C盘
配置环境变量: 
ANDROID          D:\Android\sdk\platform-tools D:\Android\sdk\tools
ANDROID_HOME     D:\Android\sdk
JAVA_HOME       D:\Android\jdk1.8.0_121
Path   %JAVA_HOME%\bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\nodejs\;F:\xampp\php;C:\ProgramData\ComposerSetup\bin;%ANDROID%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
运行javac

3) 安装elasticsearch  从https://www.elastic.co/downloads/past-release 
我选择了 elasticsearch-2.4.1 解压到D盘 ,管理员方式运行 elasticsearch.bat
不要关闭运行的cmd, 然后在浏览器中输入 http://localhost:9200/
能得到类似的代码,说明安装成功。

{
  "name" : "Stephen Strange",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "J2ZB1HdoQbGunLy9rgGp7Q",
  "version" : {
    "number" : "2.4.1",
    "build_hash" : "c67dc32e24162035d18d6fe1e952c4cbcbe79d16",
    "build_timestamp" : "2016-09-27T18:57:55Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.2"
  },
  "tagline" : "You Know, for Search"
}
lasticsearch扩展
执行 composer require –prefer-dist yiisoft/yiisoft/yii2-elasticsearch "*"
或者 composer.json中增加  "yiisoft/yii2-elasticsearch": "~2.0.0"

YII2中简单测试, components中:
'components' => [
   'elasticsearch' => [
     'class' => 'yii\elasticsearch\Connection',
        'nodes' => [
           ['http_address' => '127.0.0.1:9200'],
                // configure more hosts if you have a cluster
        ],
    ],
新建一个ElasticController,new一个elastic。

namespace frontend\controllers;
use frontend\models\elastic;
use yii\web\Controller;
use frontend\components\FrontendController;
class ElasticController extends FrontendController
{
 public function actionIndex()
 {
 $elastic = new elastic();
 $elastic->name = 'ahmed';
 $elastic->email = 'ahmedkhan_847@hotmail.com';
 if ($elastic->insert()) {
 echo "Added Successfully";
 } else {
 echo "Error";
 }
 }
}
运行至控制器 输出Added Successfully 说明ok

Previous Post电商广告图常用设计技巧剖析
Next Post庆祝下我的Ionic3&Angular4复合型App开工