ELK(二)ElasticSearch

版本:ElasticSearch-7.*

1.ElasticSearch 与 关系型数据 对比

关系型数据库(MySQL)非关系型数据库(ElasticSearch)
数据库(Database)索引(Index)
表(Table)类型(Type)
数据行(Row)文档(Document)
数据列(Column)字段(Field)
约束(Schema)映射(Mapping)
PUT
DELETE
POST
GET

2.查询基础状态

# 查询集群是否健康,9200端口是否可用
$ curl localhost:9200/_cat/health

# 查询集群的节点列表
$ curl localhost:9200/_cat/nodes

-s 忽略curl的统计信息
?pretty 格式化输出

3.索引 index

索引 index 是存储 document 文档数据的结构,意义类似于关系型数据库中的数据库。

# 查看所有索引
# 结果从左至右依次为
# 1health 2status 3index 4pri 5rep 6docs.count
# 7docs.deleted 8store.size 9pri.store.size
$ curl -s localhost:9200/_cat/indices?v

# 查看所有索引,只查看索引状态和索引名称
$ curl -s localhost:9200/_cat/indices | awk '{print $1,$3}'

# 查看单个索引
$ curl -s localhost:9200/索引名?pretty

# 创建索引
$ curl -s -H "Content-Type: application/json" -XPUT localhost:9200/索引名?pretty

# 删除索引
$ curl -s -XDELETE localhost:9200/索引名?pretty

# 关闭索引
$ curl -s -XPOST localhost:9200/索引名/_close?pretty

# 打开索引
$ curl -s -XPOST localhost:9200/索引名/_open?pretty

# 查看索引中的文档数
$ curl -s localhost:9200/索引名/_count?pretty

4.类型 type

类型 type: 也用于存储 document 的逻辑结构,相对于index来说,type 是 index 的下级,所以通常在面向有实际意义的数据时,index 作为大类的划分,type 作为小类的划分。(type 在 es6 之后会逐渐被抛弃)

5.文档 document

文档 document: 是 json 格式的。

  • 对于文档,有几个主要的标识信息:_index(插入到哪个索引中),_type(插入到哪个类型中),_id(文档的id)。
# 创建文档
# 方式一:curl -XPUT ip:9200/{index}/_doc/{id} -d 内容
# 方式二:curl -XPUT ip:9200/{index}/_doc -d 内容
# (方式二是自动生成id,例:KvFpN30B0kLieYHGqmtk)
# 方式三:curl -XPUT ip:9200/{index}/_create/{id} -d 内容
$ curl -H "Content-Type:application/json" -XPUT localhost:9200/index/_create/1?pretty -d '{"name":"John Doe"}'

# 查看文档
$ curl localhost:9200/index/_doc/1?pretty

# 修改文档
$ curl -H "Content-Type:application/json" -XPOST localhost:9200/index/_doc/1/_update -d '{"需要修改的key":"想要修改成的value"}'

# 删除文档
$ curl -XDELETE localhost:9200/index/_doc/1

# 查看所有文档
$ curl localhost:9200/index/_search
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不愿放下技术的小赵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值