在我的ElasticSearch中,使用日期后缀创建一个新的metricbeat索引。即“metricbeat-7.1-2019.12.20”。现在,我正在尝试从最新创建的索引中读取系统参数,但不确定如何执行此操作。
var nodes = new Uri[]
{
new Uri(_options.Value.ElasticSearchUrl),
};
connectionPool = new StaticConnectionPool(nodes);
string indexName = "metricbeat*";
connectionSettings = new ConnectionSettings(connectionPool).DefaultIndex(indexName);
elasticClient = new ElasticClient(connectionSettings);
string[] systemFields = new string[]
{
"system.memory.*"
};
var elasticResponse = elasticClient.Search<object>(s => s
.DocValueFields(dvf => dvf.Fields(systemFields)));
elasticResponse给了我数据,但它显示了时间戳中的较早日期。
请提出建议。
string[] systemFields = new string[]
{
"system.memory.actual.used.pct",
"system.cpu.total.norm.pct",
"system.load.5",
"docker.diskio.summary.bytes"
};
var elasticResponse = elasticClient.Search<object>(s => s
.DocValueFields(dvf => dvf.Fields(systemFields))
.Aggregations(ag => ag.Max("last_process_time", sa => sa
.Field("@timestamp")))
);
最佳答案
Cat indices API将创建日期用作排序参数,可以帮助您找到所需的索引。
await client.Indices.CreateAsync("metricbeat-7.1-2019.12.20", create => create);
await client.Indices.CreateAsync("metricbeat-7.1-2019.12.21", create => create);
var response = await client.Cat.IndicesAsync(i => i.Index("metricbeat-7.1-*")
.Headers("index", "creation.date")
.SortByColumns("creation.date"));
Console.WriteLine(response.Records.LastOrDefault()?.Index);
输出:
metricbeat-7.1-2019.12.21
希望您为索引定义了ILM policy,但我的解决方案不会找回
来自Elasticsearch的数千种索引信息。
希望能有所帮助。
关于elasticsearch - 如何在ElasticSearch中读取最新索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59559815/