- 1.ElasticSearch 与 关系型数据 对比
- 2.查询基础状态
- 3.索引 index
- 4.类型 type
- 5.文档 document
1.ElasticSearch 与 关系型数据 对比版本:ElasticSearch-7.*
| 关系型数据库(MySQL) | 非关系型数据库(ElasticSearch) |
|---|---|
| 数据库(Database) | 索引(Index) |
| 表(Table) | 类型(Type) |
| 数据行(Row) | 文档(document) |
| 数据列(Column) | 字段(Field) |
| 约束(Schema) | 映射(Mapping) |
| 增 | PUT |
| 删 | DELETE |
| 改 | POST |
| 查 | GET |
# 查询集群是否健康,9200端口是否可用 $ curl localhost:9200/_cat/health # 查询集群的节点列表 $ curl localhost:9200/_cat/nodes
3.索引 index-s 忽略curl的统计信息
?pretty 格式化输出
索引 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
5.文档 document类型 type: 也用于存储 document 的逻辑结构,相对于index来说,type 是 index 的下级,所以通常在面向有实际意义的数据时,index 作为大类的划分,type 作为小类的划分。(type 在 es6 之后会逐渐被抛弃)
文档 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



