一。下载ElasticSearch 6.6.2
下载地址:https://www.elastic.co/cn/downloads/past-releases#elasticsearch
二。启动ElasticSearch
1. 将下载好的压缩文件解压,然后cd /Users/sunww/Documents/JAVA/elasticsearch-6.6.2/bin
2. 执行bin下的elasticsearch 启动ES
3. 启动执行情况,如下图ES已经正常启动了
[2019-07-03T11:23:32,541][INFO ][o.e.t.TransportService ] [szjihGQ] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
ES启动了一个Tcp的服务且端口在9300上
[2019-07-03T11:23:35,672][INFO ][o.e.h.n.Netty4HttpServerTransport] [szjihGQ] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
ES启动了一个Http的服务且端口在9200上
三. 查看ES运行情况
在浏览器中打开 http://localhost:9200
可以看到如下 图,说明ES已经正常启动并运行了
四。测试添加记录与查询记录
添加3条记录
curl -XPUT 'http://localhost:9200/twitter/_doc/1?pretty' -H 'Content-Type: application/json' -d '
{
"user": "kimchy",
"post_date": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}'
curl -XPUT 'http://localhost:9200/twitter/_doc/2?pretty' -H 'Content-Type: application/json' -d '
{
"user": "kimchy",
"post_date": "2009-11-15T14:12:12",
"message": "Another tweet, will it be indexed?"
}'
curl -XPUT 'http://localhost:9200/twitter/_doc/3?pretty' -H 'Content-Type: application/json' -d '
{
"user": "elastic",
"post_date": "2010-01-15T01:46:38",
"message": "Building the site, should be kewl"
}'
查询刚刚添加的语句
curl -XGET 'http://localhost:9200/twitter/_doc/1?pretty=true'
curl -XGET 'http://localhost:9200/twitter/_doc/2?pretty=true'
curl -XGET 'http://localhost:9200/twitter/_doc/3?pretty=true'
在终端中输入上面的部分测试截图: