本文共 4272 字,大约阅读时间需要 14 分钟。
在日常的工作和学习中,例如学习一个新技术,经常需要安装一些程序,那么这个时候,最推荐的就是区技术的官网,学习最新的安装方法,进行安装。
关于Elasticsearch的安装,在官网安装解释中说的很明确。
其他版本的我暂时没有验证过,我在此仅验证一下Mac版本的。brew install elasticsearch
这样就安装完了:
==> Downloading https://artifacts.elastic.co/downloads/elasticsearch/elasticsear######################################################################## 100.0%==> CaveatsData: /usr/local/var/lib/elasticsearch/elasticsearch_wangdong/Logs: /usr/local/var/log/elasticsearch/elasticsearch_wangdong.logPlugins: /usr/local/var/elasticsearch/plugins/Config: /usr/local/etc/elasticsearch/To have launchd start elasticsearch now and restart at login: brew services start elasticsearchOr, if you don't want/need a background service you can just run: elasticsearch==> Summary? /usr/local/Cellar/elasticsearch/6.2.4: 112 files, 30.8MB, built in 8 minutes 19 seconds~ ⌚ 16:02:02$
只需要在命令行输入:elasticsearch就可以启动
$ elasticsearchJava HotSpot(TM) 64-Bit Server VM warning: Cannot open file logs/gc.log due to No such file or directory.....[2018-07-18T16:02:55,520][INFO ][o.e.t.TransportService ] [co8Ssev] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}[2018-07-18T16:02:58,636][INFO ][o.e.c.s.MasterService ] [co8Ssev] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {co8Ssev}{co8SsevGRTWDhnyjFsSD9A}{Pv9vnbYTQfaI-c4kxzYF3Q}{127.0.0.1}{127.0.0.1:9300}[2018-07-18T16:02:58,640][INFO ][o.e.c.s.ClusterApplierService] [co8Ssev] new_master {co8Ssev}{co8SsevGRTWDhnyjFsSD9A}{Pv9vnbYTQfaI-c4kxzYF3Q}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {co8Ssev}{co8SsevGRTWDhnyjFsSD9A}{Pv9vnbYTQfaI-c4kxzYF3Q}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])[2018-07-18T16:02:58,656][INFO ][o.e.h.n.Netty4HttpServerTransport] [co8Ssev] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}[2018-07-18T16:02:58,656][INFO ][o.e.n.Node ] [co8Ssev] started[2018-07-18T16:02:58,658][INFO ][o.e.g.GatewayService ] [co8Ssev] recovered [0] indices into cluster_state
如果要后台运行,请参考。
如果你要操作Elasticsearch的话,就不能够直接通过命令行了!
你如你在这边官方文档,会看到一些操作。 例如:/_cat/health?v
中间没有空格。GET /_cat/health?v
对应的数据的意思,请看官方文档。
GET /_cat/nodes?v
GET /_cat/indices?v
下面意思是,我们目前的集群中没有索引。
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
标准格式:
<REST Verb> /<Index>/<Type>/<ID>
两种方式:
1:PUT /customer
2:
PUT /customer?pretty
注意索引是唯一的,错误会执行报错
{ "error": { "root_cause": [ { "type": "resource_already_exists_exception", "reason": "index [customer/9q9iDbOqQgSdlqxPENkEBA] already exists", "index_uuid": "9q9iDbOqQgSdlqxPENkEBA", "index": "customer" } ], "type": "resource_already_exists_exception", "reason": "index [customer/9q9iDbOqQgSdlqxPENkEBA] already exists", "index_uuid": "9q9iDbOqQgSdlqxPENkEBA", "index": "customer" }, "status": 400}
执行:
GET /_cat/indices?v
响应:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.sizeyellow open customer 9q9iDbOqQgSdlqxPENkEBA 5 1 0 0 1.1kb 1.1kb
第二个命令的结果告诉我们,我们现在有一个名为customer的索引,它有5个主分片和1个副本(默认值),并且它包含0个文档。
您可能还注意到客户索引标记了黄色运行状况。回想一下我们之前的讨论,黄色表示某些副本尚未(尚未)分配。此索引发生这种情况的原因是因为默认情况下Elasticsearch为此索引创建了一个副本。由于我们目前只有一个节点在运行,因此在另一个节点加入集群的较晚时间点之前,尚无法分配一个副本(用于高可用性)。将该副本分配到第二个节点后,此索引的运行状况将变为绿色。
给customer的索引添加数据,因为ES是以文档Json格式在存储,索引后面写个_doc,给它一个ID是1。
PUT /customer/_doc/1?pretty{ "name": "John Doe"}注意:同一个ID,在PUT的时候,是会去覆盖的,相当于更改,version字段就是这个ID更改的次数
执行:
GET /customer/_doc/1?pretty
响应:
{ "_index": "customer", "_type": "_doc", "_id": "1", "_version": 7, "found": true, "_source": { "name": "熊 本" }}
执行
两种方式 1:DELETE /customer
2:
DELETE /customer?pretty
再执行查看索引:
GET /_cat/indices?v
响应:
说明此时现在已经没有索引了。health status index uuid pri rep docs.count docs.deleted store.size pri.store.sizegreen open .kibana WZ_XKyA3RfaGIXiW3D4z-Q 1 0 1 0 13.1kb 13.1kb
结语:好的,后续再进一步分享一些更加高深的东西。