创建索引
PUT /comma_analyzer_demo
{
"mappings": {
"properties": {
"info":{
"type": "text",
"analyzer": "ik_smart"
}
}
}
}
查询索引
#查询索引映射
GET /comma_analyzer_demo/_mapping
#查询索引设置
GET /comma_analyzer_demo/_settings
删除索引
DELETE /comma_analyzer_demo
修改索引
- 用新的索引配置创建索引
- 重建索引,从旧索引导入数据到新索引
- 删除原索引
- 设置别名,无缝切换
# 用新的索引配置创建索引
PUT comma_analyzer_demo1
{
"settings": {
"analysis": {
"analyzer": {
"comma": {
"type": "pattern",
"pattern": ","
}
}
}
},
"mappings": {
"properties": {
"info" : {
"type" : "text",
"analyzer": "comma",
"search_analyzer": "comma",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
# 从旧索引导入数据到新索引
POST _reindex
{
"source": {
"index": "comma_analyzer_demo"
},
"dest": {
"index": "comma_analyzer_demo1"
}
}
# 删除原索引
DELETE /comma_analyzer_demo
# 设置别名
PUT /comma_analyzer_demo1/_alias/comma_analyzer_demo
添加或更新数据
POST /comma_analyzer_demo1/_doc/1
{
"info":"中间件工程师,虚拟化工程师,数据库工程师,存储工程师,网络工程师,系统测试工程师,运维工程师"
}
查询分词结果
GET _analyze
{
"analyzer": "ik_smart",
"text":"中间件工程师,虚拟化工程师,数据库工程师,存储工程师,网络工程师,系统测试工程师,运维工程师"
}
查询索引某条记录某个字段实际的分词结果
GET /${index}/${type}/${id}/_termvectors?fields=${fields_name}
# 例如:
GET /comma_analyzer_demo1/_doc/1/_termvectors?fields=info
查看别名都指向哪些索引
GET /*/_alias/comma_analyzer_demo
平滑切换索引
POST /_aliases
{
"actions": [{
"remove": {
"index": "topic_v1",
"alias": "topic_alias"
}
}, {
"add": {
"index": "topic_v2",
"alias": "topic_alias"
}
}]
}