有别于关系型数据库的字段存储。es的document用json数据格式来表达,面向文档存储。
集群的健康状况:GET /_cat/health?v
查看所有索引:GET /_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open .kibana YTDY7pmFRFu4HaXWz5D9qw 1 0 1 0 4kb 4kb
green:每个索引的primary shard和replica shard都是active状态的
yellow:每个索引的primary shard都是active状态的,但是部分replica shard不是active状态,处于不可用的状态
red:不是所有索引的primary shard都是active状态的,部分索引有数据丢失了
为了容错,primary shard和replica shard是不允许在同一台机器上。在7.0.0中,默认的分片数量将从[5]更改为[1],之前版本是默认5个primary shard + 5个replica shard
创建索引:PUT /test_index?pretty
获取索引信息:GET /test_index
删除索引:DELETE /test_index?pretty
es会自动建立index和type,不需要提前创建,而且es默认会对document每个field都建立倒排索引,让其可以被搜索。
## 插入文档 or 替换更新文档
PUT /hero/hero/1
{
"name" : "wu song",
"alias" : "xing zhe",
"power" : 80,
"tags": [ "kill tiger", "panjinlian" ]
}
## 获取文档
GET /hero/hero/1
{
"_index": "hero",
"_type": "hero",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"name": "wu song",
"alias": "xing zhe",
"power": 80,
"tags": [
"kill tiger",
"panjinlian"
]
}
}
## 更新文档,相比较PUT方式,不需要带上所有field
POST /hero/hero/1/_update
{
"doc": {
"tags": ["kill tiger","wuerlang"]
}
}
## 删除文档
DELETE /hero/hero/1