常用的 REST API 向 Elasticsearch 发送数据和其他请求:
1.创建索引生命周期管理 (ILM) 策略
curl -X PUT "localhost:9200/_ilm/policy/log_test_policy/" -H 'Content-Type: application/json' -d'
{
"policy": {
"phases": {
"hot": {
"actions": {
"rollover": {
"max_age": "30d",
"max_size": "100gb"
}
}
},
"delete": {
"min_age": "30d",
"actions": {
"delete": {}
}
}
}
}
}
2.创建模板
curl -X PUT "localhost:9200/_template/log_test_template/" -H 'Content-Type: application/json' -d'
{
"index_patterns": ["log_test-*"],
"settings": {
"index.lifecycle.name": "log_test_policy",
"index.lifecycle.rollover_alias": "log_test",
"index.number_of_shards": "3",
"index.number_of_replicas": "1"
},
"mappings": {
"properties": {
"@timestamp": {
"type": "date"
}
}
}
}
3.创建一个索引
curl -X PUT "localhost:9200/log_test-000001/" -H 'Content-Type: application/json' -d'
{
"aliases": {
"log_test":{
"is_write_index": true
}
}
}
4.删除索引
curl -X DELETE "localhost:9200/log_test-*"
5.获取索引信息
GET /_cat/indices
6.获取某个索引的映射关系
GET /索引名/_mapping
7.使用ILM explain API来监测任务进程
GET /索引名*/_ilm/explain?pretty
8.获取具体某个索引的信息
GET /单个索引名
例如:
在响应结果中可以查找【creation_date】,对于自动生成的索引,这个字段对应的时候,就是该索引创建的时间。