建一个索引的步骤

1:先创建轮滚策略

2:创建模板

3:创建索引

 

创建轮滚策略

PUT _ilm/policy/this_is_an_index_policy
{
    
    "policy" : {
      "phases" : {
        "hot" : {
          "min_age" : "0ms",
          "actions" : {
            "rollover" : {
              "max_size" : "100gb",
              "max_age" : "7d"
            }
          }
        },
        "delete" : {
          "min_age" : "7300d",
          "actions" : {
            "delete" : { }
          }
        }
      }
    }
} 

 获取模板

GET _ilm/policy/experience_manager_platform_policy

创建索引模板

PUT /_template/this-is-an-index-template
{
    "order" : 0,
    "index_patterns" : [
      "this-is-an-index-*"
    ],
    "settings" : {
      "index" : {
        "lifecycle" : {
          "name" : "this_is_an_index_policy",  # 这里要指向刚才创建的轮滚策略
          "rollover_alias" : "this-is-an-index"  # 这个是轮滚后的索引的别名
        },
        "search" : {
          "slowlog" : {
            "level" : "info",
            "threshold" : {
              "fetch" : {
                "warn" : "800ms",
                "info" : "300ms"
              },
              "query" : {
                "warn" : "800ms",
                "info" : "300ms"
              }
            }
          }
        },
        "refresh_interval" : "60s",
        "number_of_shards" : "6",
        "number_of_replicas" : "1"
      }
    },
    "mappings" : {
      "dynamic" : "false",
      "properties" : {
        "os_info" : {
          "type" : "keyword"
        },
        "app" : {
          "type" : "keyword"
        },
        "content" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "ignore_above" : 256,
              "type" : "keyword"
            }
          }
        },
        "province" : {
          "type" : "keyword"
        }
      }
    },
    "aliases" : {}
  }

根据模板创建索引

PUT /this-is-an-index-000001

{
    "aliases": {
        "this-is-an-index": {
            "is_write_index": true
        }
    }
}

 

创建索引后,如果要观察轮滚效果,可以手动滚动

POST /this-is-an-index/_rollover

 

修改mapping后数据操作:

update by query

POST /my-index/_update_by_query?conflicts=proceed
{
  "script": {
    "source": "ctx._source.new_field = ctx._source.old_field",
    "lang": "painless"
  },
  "query": {
    "exists": { "field": "old_field" }
  }
}

reindex

POST _reindex
{
    "source": {
        "index": "index-v1",
        "query": {
            "range": {
                "created_at": {
                    "gte": <一个时间点>
                }
            }
        }
    },
    "dest": {
        "index": "index-v2"
    }
}

 

 

ref: https://www.cnblogs.com/sanduzxcvbnm/p/12085103.html

https://bennhuang.com/posts/es-mapping/

posted on 2021-12-18 17:30  Go_Forward  阅读(189)  评论(0编辑  收藏  举报