curl 127.0.0.1:9200/_cat/indices
PUT /my_index
{
"settings": { ... any settings ... }
}
// 文章索引
curl -X PUT 127.0.0.1:9200/articles -H 'Content-Type: application/json' -d'
{
"settings" : {
"index": {
"number_of_shards" : 3, # 主分片数
"number_of_replicas" : 1 # 从数据库数量
}
}
}
'
# 查看索引库
curl 127.0.0.1:9200/_cat/indices
curl -X DELETE 127.0.0.1:9200/articles
curl -X PUT 127.0.0.1:9200/articles/_mapping/article -H 'Content-Type: application/json' -d'
{
"_all": {
"analyzer": "ik_max_word"
},
"properties": {
"article_id": {
"type": "long",
"include_in_all": "false"
},
"user_id": {
"type": "long",
"include_in_all": "false"
},
"title": {
"type": "text",
"analyzer": "ik_max_word",
"include_in_all": "true",
"boost": 2
},
"content": {
"type": "text",
"analyzer": "ik_max_word",
"include_in_all": "true"
},
"status": {
"type": "integer",
"include_in_all": "false"
},
"create_time": {
"type": "date",
"include_in_all": "false"
}
}
}
'
curl 127.0.0.1:9200/articles?pretty # 查询整个索引库结构
curl 127.0.0.1:9200/articles/_mapping/article?pretty # 查询article表的结构
# 不设置-X默认为GET
# 创建新的索引库 5.x版本分别设置配置和类型映射
curl -X PUT 127.0.0.1:9200/articles_v2 -H 'Content-Type: application/json' -d'
{
"settings" : {
"index": {
"number_of_shards" : 3,
"number_of_replicas" : 1
}
}
}
'
curl -X PUT 127.0.0.1:9200/articles_v2/_mapping/article -H 'Content-Type: application/json' -d'
{
"_all": {
"analyzer": "ik_max_word"
},
"properties": {
"article_id": {
"type": "long",
"include_in_all": "false"
},
"user_id": {
"type": "long",
"include_in_all": "false"
},
"title": {
"type": "text",
"analyzer": "ik_max_word",
"include_in_all": "true",
"boost": 2
},
"content": {
"type": "text",
"analyzer": "ik_max_word",
"include_in_all": "true"
},
"status": {
"type": "byte",
"include_in_all": "false"
},
"create_time": {
"type": "date",
"include_in_all": "false"
}
}
}
# 重新索引数据
curl -X POST 127.0.0.1:9200/_reindex -H 'Content-Type:application/json' -d '
{
"source": {
"index": "articles"
},
"dest": {
"index": "articles_v2"
}
}
'
起别名
curl -X DELETE 127.0.0.1:9200/articles # 先删除原索引库
curl -X PUT 127.0.0.1:9200/articles_v2/_alias/articles # 给索引库起别名, 设置为原索引库的名称
# 查看别名指向哪个索引
curl 127.0.0.1:9200/*/_alias/articles
# 查看哪些别名指向这个索引
curl 127.0.0.1:9200/articles_v2/_alias/*
原文:https://www.cnblogs.com/oklizz/p/11443274.html