在我的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的数千种索引信息。
希望有所帮助。