使用方法:请在kibana的DevTool(开发工具)页面运行以下命令
注:mysql_mall_prod
、temp
等均为索引名、prod_name
为字段名,其余字符均为es、ik分词器关键字。
POST /_cluster/reroute
# 设置副分片数量
PUT mysql_mall_prod/_settings
{
"index": {
"number_of_replicas": 0
}
}
# 解释给定分片的当前分配情况和逻辑,primary表示查看主分片/副本
GET _cluster/allocation/explain
{
"index": "mysql_mall_prod",
"shard": 0,
"primary": false
}
# 查找unassigned(未分配)原因
GET /_cat/shards?v&h=n,index,shard,prirep,state,sto,sc,unassigned.reason,unassigned.details&s=sto,index
GET /_cat/indices?v&health=yellow
# 根据_id查找指定索引
GET mysql_mall_prod/_doc/104
GET temp/_doc/_search
POST mysql_mall_prod/_doc/_search
{
"query": {
"match" : {
"prod_name": "华为手机"
}
}
}
POST /_analyze
{
"analyzer": "ik_max_word",
"text":"华为手机"
}
# 打开索引:
POST mysql_mall_prod/_open
# 关闭索引:
POST mysql_mall_prod/_close
# 给已存在的索引添加分词器
PUT mysql_mall_prod/_settings
{
"analysis": {
"analyzer": "ik_smart",
"search_analyzer": "ik_smart"
}
}
# mapping释义:https://www.elastic.co/guide/en/elasticsearch/reference/7.17/mapping.html
# mapping参数释义:https://www.elastic.co/guide/en/elasticsearch/reference/7.17/mapping-params.html
GET mysql_mall_prod/_mapping
GET mysql_mall_prod/_settings
GET /_cluster/health
GET /_cluster/allocation/explain
POST mysql_mall_prod/_doc/_search
{
"query": {
"match":{
"prod_name":{
"query" : "华为手机",
"analyzer" : "ik_max_word"
}
}
}
}
POST mysql_mall_prod/_analyze/?pretty
{
"text": "华为手机",
"analyzer": "ik_smart"
}
# 查询索引全部数据
GET mysql_mall_prod/_search
# 建新索引
PUT temp
{
}
# 新建索引时指定mapping
PUT mysql_mall_prod
{
"mappings": {
"properties": {
"prod_name": {
"type": "text",
"analyzer": "ik_smart"
},
"create_time": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd'T'HH:mm:ss'+08:00' || strict_date_optional_time || epoch_millis"
},
"update_time": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd'T'HH:mm:ss'+08:00' || strict_date_optional_time || epoch_millis"
},
"putaway_ime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd'T'HH:mm:ss'+08:00' || strict_date_optional_time || epoch_millis"
}
}
}
}
# 为索引添加mapping,注意不能修改修改已存在的mapping,要修改请使用reindex
PUT temp/_mapping
{
"properties": {
"prod_name": {
"type": "text",
"analyzer": "ik_smart"
}
}
}
# 索引迁移,也可用于重命名。但是似乎无法修改dest中已经存在的mapping
POST /_reindex
{
"source": {
"index": "mysql_mall_prod"
},
"dest": {
"index": "temp"
}
}
# 索引别名,相当于重命名
POST _aliases
{
"actions": [
{
"add": {
"index": "temp",
"alias": "temp-new"
}
}
]
}