es 使用模板创建索引

创建模板:

PUT _template/metric_datatest

{
	"index_patterns": ["metric_datatest-*"],
	"order": 0,
	"settings": {
		"analysis": {
			"analyzer": {
				"tags_analyzer": {
					"type": "pattern",
					"pattern": ","
				}
			}
		}
	},
	"mappings": {
		"properties": {
			"ts": {
				"type": "long"
			},
			"name": {
				"type": "keyword"
			},
			"tags": {
				"type": "text",
				"analyzer": "tags_analyzer"
			},
			"count": {
				"type": "long"
			},
			"sum": {
				"type": "double"
			},
			"max": {
				"type": "double"
			},
			"min": {
				"type": "double"
			}
		}
	},
	"aliases": {
		"metric_datatest": {}
	}
}

使用模板创建索引,不用指定mappings和settings:

PUT /metric_datatest-2021-04-16

插入需要指定具体的索引名,查询时只要使用别名metric_datatest就可以,可以并发查询别名对应的所有索引。

不使用模板创建索引

PUT /metric_data
{
  "settings": {
    "analysis": {
      "analyzer": {
        "tags_analyzer": {
          "type": "pattern",
          "pattern": ","
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "ts": {
        "type": "long"
      },
      "name": {
        "type": "keyword"
      },
      "tags": {
        "type": "text",
        "analyzer": "tags_analyzer"
      },
      "count": {
        "type": "long"
      },
      "sum": {
        "type": "double"
      },
      "max": {
        "type": "double"
      },
      "min": {
        "type": "double"
      }
    }
  }
}

 

原文地址:https://www.cnblogs.com/yaoyu1983/p/14667911.html