我正在尝试从24小时之前创建的elasticsearch中删除索引。我没有找到获取特定节点索引创建时间的方法。使用 Spring 靴 Elasticsearch 可以实现。但是我正在使用Jest API。
最佳答案
您可以获取在创建索引时存储的settings.index.creation_date
值。
使用curl可以使用以下命令轻松获得它:
curl -XGET localhost:9200/your_index/_settings
你得到:
{
"your_index" : {
"settings" : {
"index" : {
"creation_date" : "1460663685415", <--- this is what you're looking for
"number_of_shards" : "5",
"number_of_replicas" : "1",
"version" : {
"created" : "1040599"
},
"uuid" : "dIG5GYsMTueOwONu4RGSQw"
}
}
}
}
使用Jest,您可以使用以下方法获得相同的值:
import io.searchbox.indices.settings.GetSettings;
GetSettings getSettings = new GetSettings.Builder().build();
JestResult result = client.execute(getSettings);
然后,您可以使用
JestResult
来查找creation_date
如果我有什么建议,curator将是实现您所需功能的便捷工具。
只需每天运行一次:
curator delete indices --older-than 1 --time-unit days
关于elasticsearch - 如何使用Jest在 Elasticsearch 中获取索引的创建时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36913169/