如何使用 Jest 在弹性搜索中获取索引的创建时间
How to get creation time of indices in elastic search using Jest
我正在尝试从 elasticsearch 中删除 24 小时前创建的索引。我没有找到一种方法来获取特定节点的索引创建时间。使用spring boot elastic search,可以做到这一点。但是,我正在使用 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 中删除 24 小时前创建的索引。我没有找到一种方法来获取特定节点的索引创建时间。使用spring boot elastic search,可以做到这一点。但是,我正在使用 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