Elasticsearch必知必会的干货知识二:ES索引操作技巧

  • index自动滚动【Rollover】,即:当索引达到预设的滚动条件时,会自动创建新的索引(index),并将别名(alias)指向最新的索引,原索引将被自动删除映射,如:(先创建索引并指名索引别名,然后执行_rollover API 且设定滚动的条件值,最后正常的插入文档数,当达到滚动条件后,则会自动触发index _rollover)

    POST index_alias_name/_rollover/
    {
      "conditions": {
        "max_age": "7d", //设置:最大时间7天
        "max_docs": 10000,//设置:最大文档记录数
        "max_size":  "5gb" //设置:索引最大容量
      }
    }
    
    //Response:
    {
      "old_index": "旧索引名",
      "new_index": "新索引名",
      "rolled_over": true,
      "dry_run": false,
      "acknowledged": true,
      "shards_acknowledged": true,
      "conditions": {
        "[max_docs: 10000]": true,
        "[max_age: 7d]": false,
        "[max_size: 5gb]": false
      }
    }
    
    //POST index_alias_name/_doc -d {index文档JSON}  插入10000以上的文档记录