C# ElasticSearch-嵌套-嵌套在列表和字典中的映射命中
TLDR:我如何获得我需要的数据,使其像时间戳一样位于C# ElasticSearch-嵌套-嵌套在列表和字典中的映射命中,c#,
elasticsearch,nest,metricbeat,C#,
elasticsearch,Nest,Metricbeat,TLDR:我如何获得我需要的数据,使其像时间戳一样位于源代码中,而不是位于一百万个列表和字典中 我正试图从这个嵌套查询中创建数据对象。数据来自MetricBeats,并在我的响应中的许多嵌套列表和字典中结束。正如您在JSON响应中看到的那样,点击 我通常会使用此方法直接映射我的点击: foreach (Hit<Data> item in dataResponse) { Data d = item.Source; } 这就是我现在正在做的,用查询中的数据创建一个Data
源代码中,而不是位于一百万个列表和字典中
我正试图从这个嵌套查询中创建数据对象。数据来自MetricBeats,并在我的响应中的许多嵌套列表和字典中结束。正如您在JSON响应中看到的那样,点击
我通常会使用此方法直接映射我的点击:
foreach (Hit<Data> item in dataResponse)
{
Data d = item.Source;
}
这就是我现在正在做的,用查询中的数据创建一个Data
对象。这显然可以用一种不同的、更有效的方式来实现
foreach (Hit<dynamic> item in dataResponse)
{
Dictionary<string, dynamic> test = item.Source;
test.TryGetValue("host", out var host);
Dictionary<string, dynamic> test2 = host;
test2.TryGetValue("network", out var network);
Dictionary<string, dynamic> test3 = network;
test3.TryGetValue("in", out var input);
Dictionary<string, dynamic> test4 = input;
test4.TryGetValue("bytes", out var final);
test.TryGetValue("@timestamp", out dynamic time);
string test145 = time;
long test144 = final;
Data d = new Data
{
Bytes = test144,
Timestamp = test145
};
Console.WriteLine(d.Bytes);
data.Add(d);
Console.WriteLine(data);
}
foreach (Hit<dynamic> item in dataResponse)
{
Dictionary<string, dynamic> test = item.Source;
test.TryGetValue("host", out var host);
Dictionary<string, dynamic> test2 = host;
test2.TryGetValue("network", out var network);
Dictionary<string, dynamic> test3 = network;
test3.TryGetValue("in", out var input);
Dictionary<string, dynamic> test4 = input;
test4.TryGetValue("bytes", out var final);
test.TryGetValue("@timestamp", out dynamic time);
string test145 = time;
long test144 = final;
Data d = new Data
{
Bytes = test144,
Timestamp = test145
};
Console.WriteLine(d.Bytes);
data.Add(d);
Console.WriteLine(data);
}
public class Data
{
public string Timestamp { get; set; }
public long Bytes { get; set; }
}