阅读完需:约 3 分钟
一种软件架构风格,而不是标准,只是提供了一组设计原则和约束条件。它主要用于客户端和服务器交互类的软件。基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机制。
基本Rest命令说明:

基础测试
首先我们浏览器 http://localhost:5601/ 进入 kibana里的Console
// 命令解释
// PUT 创建命令 test1 索引 type1 类型 1 id
PUT /test1/type1/1
{
"name":"xjh", // 属性
"age":16 // 属性
}
#! Deprecation: [types removal] Specifying types in document index requests is deprecated, use the typeless endpoints instead (/{index}/_doc/{id}, /{index}/_doc, or /{index}/_create/{id}).
// 警告信息:不支持在文档索引请求中指定类型 // 而是使用无类型的端点(/{index}/_doc/{id}, /{index}/_doc,或 /{index}/_create/{id})。
{
"_index" : "test1", // 索引
"_type" : "type1", // 类型
"_id" : "1", // id
"_version" : 2, // 版本
"result" : "updated", // 操作类型
"_shards" : { // 分片信息
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1
}
那么 name 这个字段用不用指定类型呢。毕竟我们关系型数据库 是需要指定类型的啊 !
- 字符串类型
text 、 keyword - 数值类型
long, integer, short, byte, double, flfloat, half_flfloat, scaled_flfloat - 日期类型
date - te布尔值类型
boolean - 二进制类型
binary - 等等……
指定字段类型
PUT /test2
{
"mappings": {
"properties": {
"name":{
"type": "text"
},
"age":{
"type": "long"
},
"birthday":{
"type": "date"
}
}
}
}
查看一下索引字段
GET test2
{
"test2" : {
"aliases" : { },
"mappings" : {
"properties" : {
"age" : {
"type" : "long"
},
"birthday" : {
"type" : "date"
},
"name" : {
"type" : "text"
}
}
},
"settings" : {
"index" : {
"creation_date" : "1608465946096",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "YVNDsNbXRIejsP3PX_Vwdw",
"version" : {
"created" : "7080099"
},
"provided_name" : "test2"
}
}
}
}
不定义类型
我们看上列中 字段类型是我自己定义的 那么 我们不定义类型 会是什么情况呢?
PUT /test3/_doc/1
{
"name":"xjh",
"age":13,
"birthdaya":"1999-05-08"
}
输出:
{
"_index" : "test3",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
查看一下test3索引:
GET test3
{
"test3" : {
"aliases" : { },
"mappings" : {
"properties" : {
"age" : {
"type" : "long"
},
"birthdaya" : {
"type" : "date"
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1608466093781",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "g9jxwGPAS9uJxDAEnLCwUA",
"version" : {
"created" : "7080099"
},
"provided_name" : "test3"
}
}
}
}
我们看上列没有给字段指定类型那么es就会默认给我配置字段类型!
对比关系型数据库 :PUT test1/type1/1 : 索引test1相当于关系型数据库的库,类型type1就相当于表 ,1 代表数据中的主键 id
这里需要补充的是 ,在elastisearch5版本前,一个索引下可以创建多个类型,但是在elastisearch5后,一个索引只能对应一个类型,而id相当于关系型数据库的主键id若果不指定就会默认生成一个20位的uuid,属性相当关系型数据库的column(列)。
而结果中的 result 则是操作类型,现在是 created ,表示第一次创建。如果再次点击执行该命令那么result 则会是 updated ,我们细心则会发现 _version 开始是1,现在你每点击一次就会增加一次。表示第几次更改。
查看索引的状态
来学一条命令 (elasticsearch 中的索引的情况) :
GET _cat/indices?v
返回结果:查看我们所有索引的状态健康情况 分片,数据储存大小等等。
