ES 学习(二)ES与关系型数据库对比

张开发
2026/4/10 20:10:07 15 分钟阅读

分享文章

ES 学习(二)ES与关系型数据库对比
目录1.ElasticSearch 与 关系型数据 对比2.查询基础状态3.索引 index4.类型 type5.文档 document版本ElasticSearch-7.*1.ElasticSearch 与 关系型数据 对比关系型数据库MySQL非关系型数据库ElasticSearch数据库Database索引Index表Table类型Type数据行Row文档Document数据列Column字段Field约束Schema映射Mapping增PUT删DELETE改POST查GET2.查询基础状态# 查询集群是否健康9200端口是否可用$curllocalhost:9200/_cat/health# 查询集群的节点列表$curllocalhost: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-slocalhost:9200/_cat/indices?v# 查看所有索引只查看索引状态和索引名称$curl-slocalhost:9200/_cat/indices|awk{print $1,$3}# 查看单个索引$curl-slocalhost:9200/索引名?pretty# 创建索引$curl-s-HContent-Type: application/json-XPUTlocalhost:9200/索引名?pretty# 删除索引$curl-s-XDELETElocalhost:9200/索引名?pretty# 关闭索引$curl-s-XPOSTlocalhost:9200/索引名/_close?pretty# 打开索引$curl-s-XPOSTlocalhost:9200/索引名/_open?pretty# 查看索引中的文档数$curl-slocalhost:9200/索引名/_count?pretty4.类型 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-HContent-Type:application/json-XPUTlocalhost:9200/index/_create/1?pretty-d{name:John Doe}# 查看文档$curllocalhost:9200/index/_doc/1?pretty# 修改文档$curl-HContent-Type:application/json-XPOSTlocalhost:9200/index/_doc/1/_update-d{需要修改的key:想要修改成的value}# 删除文档$curl-XDELETElocalhost:9200/index/_doc/1# 查看所有文档$curllocalhost:9200/index/_search

更多文章