使用curl语句es创建索引名为device_screened_alarm只保留一个月的文档数据
以下是使用curl语句在Elasticsearch中创建名为device_screened_alarm的索引,并只保留一个月的文档数据的示例:
curl -XPUT 'http://localhost:9200/device_screened_alarm' -H 'Content-Type: application/json' -d '{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0,
"lifecycle.name": "1_month"
}
},
"mappings": {
"properties": {
"device_id": {"type": "keyword"},
"alarm_type": {"type": "keyword"},
"timestamp": {"type": "date"}
}
}
}'
在上述示例中,我们使用curl语句向Elasticsearch发送PUT请求,将索引名称设置为device_screened_alarm,并设置以下配置:
- number_of_shards: 索引分片的数量,这里设置为1。
- number_of_replicas: 索引副本的数量,这里设置为0,表示没有副本。
- lifecycle.name: 索引生命周期的名称,这里设置为1_month,表示只保留一个月的文档数据。
我们还定义了索引的映射,其中包含了三个属性:
- device_id: 设备ID,类型为keyword。
- alarm_type: 告警类型,类型为keyword。
- timestamp: 时间戳,类型为date。
通过以上curl语句,我们成功创建了一个名为device_screened_alarm的索引,并将其配置为只保留一个月的文档数据
原文地址: https://www.cveoy.top/t/topic/fGE7 著作权归作者所有。请勿转载和采集!