1. 索引
1.1 什么索引
一个索引就是一个拥有几分相似特征的文档的集合。比如说,你可以有一个客户数据的索引,另一个产品目录的索引,还有一个订单数据的索引。一个索引由一个名字来标识(必须全部是小写字母的),并且当我们要对对应于这个索引中的文档进行索引、搜索、更新和删除的时候,都要使用到这个名字;
1.2 命令操作
# 查看所有索引
GET /_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open twitter c5JJhKzuS_CBv-q4xexdzw 3 2 1 0 4.6kb 4.6kb
yellow open movie SMGLbYkFRPierTNaNsbXng 3 1 3 0 13.1kb 13.1kb
yellow open weibo hqxawYAZTJqkKFkPQxMk4w 1 1 5 0 7.7kb 7.7kb
yellow open idx_locat 1CRshRsUTpKhe7Y4LEUbtg 3 2 2 0 9kb 9kb
green open .kibana_task_manager_1 MEZeVn5IQ7im2X-ljPrWzA 1 0 2 0 21.8kb 21.8kb
yellow open my_index dHN-CBpySAeD6T29Bn-MSw 1 1 0 0 283b 283b
green open .apm-agent-configuration GFZqnLa9TYOXw9MKYYD92Q 1 0 0 0 283b 283b
green open .kibana_1 zDKttXRTQAGpd3jKp3webg 1 0 9 0 32.2kb 32.2kb
# 创建索引
PUT movie
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
},
"mappings": {
"_doc": {
"properties": {
"name": {
"type": "text"
},
"type": {
"type": "keyword"
},
"country": {
"type": "text"
},
"director": {
"type": "text"
},
"date": {
"type": "date"
}
}
}
}
}
# 删除索引
DELETE weibo
#插入数据 (1代表id,不写自动设置为默认值)
POST movie/_doc/1
{
"name":"Titanic",
"type":"romance",
"country":"America",
"director":"James",
"date":"1997-12-19"
}
# 查看ID为1的数据
GET movie/_doc/1
# 结果返回
{
"_index" : "movie",
"_type" : "_doc",
"_id" : "1",
"_version" : 3,
"_seq_no" : 3,
"_primary_term" : 1,
"found" : true,
"_source" : {
"id" : "1",
"name" : "Titanic",
"type" : "Titanic",
"country" : "America",
"director" : "James",
"date" : "1997-12-19"
}
}
# 修改数据(修改id为1的director)
POST movie/_doc/1
{
"name":"Titanic",
"type":"romance",
"country":"America",
"director":"James-Cameron",
"date":"1997-12-19"
}
# 直接修改指定字段
POST movie/_update/1
{
"doc": {
"director":"Luc-Besson"
}
}
# 删除数据(删除id为1的数据)
DELETE movie/_doc/1
# 查询所有数据
GET movie/_search