ES 基本操作

0.查看集群是否健康
GET /_cluster/health

1.查询所有索引
GET /_cat/indices?v

2.查询单个索引的映射
GET /index_trans_detail/_mapping


3.删除index
DELETE /index_trans_detail,index_two

4. 添加字段映射
PUT /index_trans_detail/_mapping/type_trans_detail
{
"properties": {
"tags":{
"type": "text"
}
}
}


5. 索引的别名
5.1 创建索引的别名
PUT /index_trans_detail/_alias/index_trans_detail_alias

5.2 查询索引的别名
GET /index_trans_detail/_alias/*

5.3 查询别名指向哪一个索引
GET /*/_alias/index_trans_detail_alias

5.4 删除别名
DELETE /index_trans_detail/_alias/index_trans_detail_alias


6. 添加一个索引(通过mapping)
PUT /people
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1
  },
  "mappings": {
    "man": {
      "dynamic": "strict",
      "properties": {
        "name": {
          "type": "text"
        },
        "age": {
          "type": "integer"
        },
        "birthday": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
        },
        "address":{
          "dynamic": "true",
          "type": "object"
        }
      }
    }
  }
}
"dynamic": "strict"  表示如果遇到陌生field会报错
"dynamic": "true"   表示如果遇到陌生字段,就进行dynamic mapping
"dynamic": "false"   表示如果遇到陌生字段,就忽略

7.修改字段可以排序
PUT index_trans_detail/_mapping/activity_dictionary
{
"properties": {
"type_code":{
"type": "text",
"fielddata": true
}
}
}

7.1 添加字段
PUT /index_trans_detail/_mapping/type_trans_detail
{
"properties": {
"tags":{
"type": "text"
}
}
}

通过别名更换索引
==========================================================
8.创建别名
POST _aliases
{
"actions": [
{
"add": {
"index": "old_index",
"alias": "old_index_alias"
}
}
]
}

9.将老的索引中的数据复制到新的索引中:
POST _reindex
{
"source": {
"index": "old_index"(老的索引名)
},
"dest": {
"index": "new_index"(新的索引名)
}
}


10,创建映射
POST _aliases
{
"actions": [
{
"remove": {
"index": "old_index",
"alias": "old_index_alias"
}},
{
"add": {
"index": "new_index",
"alias": "old_index_alias"
}
}
]
}

11.删除旧索引
DELETE old_index

猜你喜欢

转载自www.cnblogs.com/zeenzhou/p/11588629.html