进入kibana页面: 宿主机ip:5601
双击Dev Tools, 输入操作命令
# -------------------------------索引------------------------------------ #
## 创建索引
PUT test_index
## 创建索引并设置副本和分片数. 副本数默认为1, 分片数默认为5 , es服务器至少2台, 副本+原版的数量和最多与es集群和服务器数量一致)
## 注: 分片数一旦确定不能更改. 副本数可以在索引创建后进行更改
PUT jt46
{
"settings": {
"number_of_replicas": 2,
"number_of_shards": 10
}
}
## 删除索引
DELETE test_index
# ---------------------------基础数据操作-------------------------------- #
## 添加数据
## 注: 一个索引(index)中只能保存一个类型(type)
### 自动id值
POST jt46/user
{
"uesrName":"apple",
"gender":0,
"age":20
}
### 指定id值
POST jt46/user/1001
{
"realName":"韩梅梅",
"password":"0000",
"age":22
}
POST jt46/user/1002
{
"id":1002,
"realName":"李雷",
"password":"0000",
"age":22
}
## 修改数据
POST jt46/user/1001/_update
{
"doc": {
"age":26
}
}
## 删除数据
DELETE jt46/user/1001
## 查询
GET jt46/_search
# ---------------------------类型映射-------------------------------- #
DELETE jt46
PUT jt46
## 设置type的映射
### 注1: 新版的es中, 每个索引(index)中只能有一个类型(type)
### 注2: es的字符串类型有2种:
### 1) keyword, 查询时内容必须完整匹配.
### 2) text, 内容按照分词器格式, 分词后创建索引. 查询时, 也按照分词索引查询
PUT jt46/user/_mapping
{
"properties": {
"id":{
"type": "integer"
},
"realName":{
"type": "keyword"
},
"age":{
"type": "integer"
},
"detail":{
"type": "text",
"analyzer": "ik_smart"
}
}
}
## 添加数据
PUT jt46/user/1001
{
"userName":"admin",
"password":"0000"
}
## 查询
GET jt46/_search
# --------------------------- 分词 -------------------------------- #
### 分词器: (3种)
#### 1) standard, 默认分词器
#### 2) ik_smart, 常用, 精简分词
#### 3) ik_max_word, 最大化分词
GET _analyze
{
"analyzer": "standard",
"text": ["如果我不二,别人会把我当做一匹狼"]
}
GET _analyze
{
"analyzer": "ik_smart",
"text": ["如果我不二,别人会把我当做一匹狼"]
}
GET _analyze
{
"analyzer": "ik_max_word",
"text": ["如果我不二,别人会把我当做一匹狼"]
}
GET _analyze
{
"analyzer": "ik_smart",
"text": ["今年看不看世界杯"]
}
GET _analyze
{
"analyzer": "ik_max_word",
"text": ["今年看不看世界杯"]
}