ES (7.10.2)学习系列之 常用命令之template

248 阅读1分钟

template

  • 上传模板 POST {{es-url}}/_template/templateName

入参

{
  "template": "test-*", // 模板匹配规则
  "order": 0, // 优先级
  "settings": {
    "index": {
      "number_of_shards": 3, // 分片数
      "number_of_replicas": 1, // 副本数
      "refresh_interval": "60s" // 刷新间隔
    }
  },
  "mappings": {
    "properties": {
      "id": {
        "type": "long"
      },
      "name": {
        "type": "keyword"
      },
      "interesting": {
        "type": "text"
      },
      "birthday":{
        "type": "date",
        "format": "yyyy-MM-dd"
      },
      "birthday_time": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss"
      }
    }
  }
}
  • 获得模板信息 GET {{es-url}}/_template/templateName?pretty

出参

{
    "test-template": {
        "order": 0,
        "index_patterns": [
            "test-*"
        ],
        "settings": {
            "index": {
                "number_of_shards": "3",
                "number_of_replicas": "1",
                "refresh_interval": "60s"
            }
        },
        "mappings": {
            "properties": {
                "birthday": {
                    "format": "yyyy-MM-dd",
                    "type": "date"
                },
                "birthday_time": {
                    "format": "yyyy-MM-dd HH:mm:ss",
                    "type": "date"
                },
                "interesting": {
                    "type": "text"
                },
                "name": {
                    "type": "keyword"
                },
                "id": {
                    "type": "long"
                }
            }
        },
        "aliases": {}
    }
}
  • 删除模板 DELETE {{es-url}}/_template/templateName