索引管理

索引管理

# 创建索引
# elasticsearch.yml  
# action.auto_create_index: false  禁止自动创建索引

PUT /my_index
{
  "settings": {},
  "mappings": {
    "type_one":{
      "properties":{
        "name":{
          "type":"text",
          "analyzer":"standard"
        }
      }
    }
  }
}

# 删除索引
# DELETE /index_one,index_two
# DELETE /index_*
# DELETE /_all
# DELETE /*
# elasticsearch.yml
# action.destructive_requires_name: true  强制使用精确索引名删除索引

DELETE /my_index

# 索引设置

PUT /index_temp_set
{
  "settings": {
    "number_of_shards": 5, // 主分片数量,索引创建后不可修改
    "number_of_replicas": 1  // 副本数量,索引创建后可以更改
  }
}

# 修改副本数

PUT /index_temp_set/_settings
{
  "number_of_replicas": 2
}

# 配置分析器

PUT /index_temp_set
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer":{
          "type":"standard",
          "stopwords":"_spanish_"
        }
      }
    }
  }
}
GET /index_temp_set/_analyze
{
  "analyzer": "my_analyzer",
  "text": ["El veloz zorro marrón"]
}

# 自定义分析器
# 字符过滤器:分词前进行字符过滤
# 分词器:进行分词
# 词单元过滤器:分词后对词进行过滤

PUT /my_index
{
  "settings": {
    "analysis": {
      "char_filter": {
        "&_to_and":{
          "type":"mapping",
          "mappings":["&=>and"]
        }
      },
      "filter": {
        "my_stopwords":{
          "type":"stop",
          "stopwords":["the", "a"]
        }
      }, 
      "analyzer": {
        "my_analyzer":{
          "type":"custom",
          "char_filter":["html_strip", "&_to_and"],
          "tokenizer":"standard",
          "filter":["lowercase","my_stopwords"]
        }
      }
    }
  }
}
GET /my_index/_analyze
{
  "analyzer": "my_analyzer",
  "text": ["<p>The quick & brown fox</p>"]
}


# 将自定义的分析器使用在文档属性上
# 属性三个重要的设置 type、analyzer、index:true/false

PUT /my_index/_mapping/my_type
{
  "properties": {
    "title":{
      "type":"text",
      "analyzer": "my_analyzer"
    }
  }
}

# 元数据
# _source字段,存储元数据
# _all,其值为大字符串的特殊值
# 搜索值在title中出现比在content中出现更重要,但是使用_all字段搜索,体现不出重要性
# 可以通过如下方式禁用_all字段

PUT /my_index/_mapping/my_type
{
    "my_type": {
        "_all": { "enabled": true }
    }
}


# 也可以手动定义定义哪些字段需要包含在_all字段中

PUT /my_index/_mapping/my_type
{
    "properties":{
      "tags":{
        "type":"text",
        "copy_to":"_all"
      }
    }
}

# 自定义动态映射
# 关闭日期检测

PUT /my_index/_mapping
{
  "date_detection":false
}

# 索引别名和零停机

PUT /my_index_v1
{
  "mappings": {
    "my_type": {
      "properties": {
        "tags":{
          "type":"keyword"
        }
      }
    }
  },
  "aliases": {
    "my_index": {}
  }
}
PUT /my_index_v2
{
  "mappings": {
    "my_type": {
      "properties": {
        "tags":{
          "type":"keyword"
        }
      }
    }
  },
  "aliases": {
    "my_index": {}
  }
}


# 查看哪些索引指向别名my_index

GET /*/_alias/my_index


# 查询my_index_v1索引指向哪个别名

GET /my_index_v1/_alias/*

# 操作别名

POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "test1",
        "alias": "alias1"
      },
      "remove": {
        "index":"test2",
        "alias":"alias2"
      }
    }
  ]
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无绪听雨眠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值