以下内容已经过时,重新整理于 https://www.isres.com/linux/117.html

由于一些原因,首次使用elasticsearch竟然是在windows上,以下是windows下的一个记录。

https://www.elastic.co/downloads/past-releases/elasticsearch-2-3-4

放C盘 解压缩

安装成服务(删除服务的命令是sc delete 服务名称)

C:\Windows\system32>cd c:\

c:\>cd elasticsearch-2.3.4\bin

c:\elasticsearch-2.3.4\bin>service.bat install
Installing service      :  "elasticsearch-service-x64"
Using JAVA_HOME (64-bit):  "C:\Program Files\Java\jdk-9.0.1"
The service 'elasticsearch-service-x64' has been installed.

c:\elasticsearch-2.3.4\bin>

这时服务就有 elasticsearch-service-x64 了

服务启动失败,查看日志 C:elasticsearch-2.3.4logs

elasticsearch-service-x64-stderr.2017-12-19.log

Java HotSpot(TM) 64-Bit Server VM warning: Option UseParNewGC was deprecated in version 9.0 and will likely be removed in a future release.

JDK9不再支持UseConcMarkSweepGC

换一个版本JDK,用旧一点的,主要是为了导数据的一个工具 elasticsearch-jdbc-master ,这个工具更新进度跟不上
ES,只得用2.3.4 去年的版本。

jdk-8u151-windows-x64.exe

安装完成后

系统环境变量 JAVA_HOME C:Program FilesJavajdk1.8.0_151

不再报这个错误了,还是没有启动成功。

elasticsearch-service-x64.2017-12-19.log

[2017-12-19 16:17:36] [error] [ 4888] Failed creating java C:Program FilesJavajdk1.8.0_151binserverjvm.dll
[2017-12-19 16:17:36] [error] [ 4888] 系统找不到指定的路径。

环境变量换成 C:Program FilesJavajre1.8.0_151

启动成功

http://localhost:9200/ 已经可以访问

但不能外部访问,配置一下

configelasticsearch.yml

network.host: 0.0.0.0

http.port: 9200

重新启动下服务

外网可访问 http://192.168.0.107:9200/

注意防火墙要开端口

配置 0.0.0.0 如果机器有公网,也会被访问


非最新版本 Elasticsearch有一个web前端交互界面Elasticsearch head插件,

我们在Elasticsearch的bin目录下运行“plugin install mobz/elasticsearch-head”命令便会自动下载

Microsoft Windows [版本 6.3.9600]
(c) 2013 Microsoft Corporation。保留所有权利。

C:\Windows\system32>cd c:\

c:\>cd elasticsearch-2.3.4

c:\elasticsearch-2.3.4>cd bin

c:\elasticsearch-2.3.4\bin>plugin install mobz/elasticsearch-head
-> Installing mobz/elasticsearch-head...
Trying https://github.com/mobz/elasticsearch-head/archive/master.zip ...
Downloading ....................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
....................DONE
Verifying https://github.com/mobz/elasticsearch-head/archive/master.zip checksum
s if available ...
NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .
md5 file to verify)
Installed head into c:\elasticsearch-2.3.4\plugins\head

c:\elasticsearch-2.3.4\bin>

http://192.168.0.107:9200/_plugin/head/ 看到UI了


创建一个所以test

在head页面中 复合查询

http://192.168.0.107:9200/test/
put

向索引中添加一条数据

PUT

http://192.168.0.107:9200/test/user/1/

{"username":"刘诗诗","age":18}

http://192.168.0.107:9200/test/user/2/

{"username":"张慧雯","age":22}

http://192.168.0.107:9200/test/user/3/

{"username":"夏晓薇","age":22}

http://192.168.0.107:9200/test/user/4/

{"username":"杨亚运","age":26}

put到同一id则可覆盖原数据 即更新
http://192.168.0.107:9200/test/user/4/
{"username":"李绮雯","age":26}

POST也可以
http://192.168.0.107:9200/test/user/5/
{"username":"高圆圆","age":28}


安装python插件可更快处理索引

pip install elasticsearch