[英]How to parse the buckets key values of an ElasticSearch Aggregations query to a list of integers in C#
這是我從ElasticSearch查詢返回的json字符串:
var response =
{
"took":1,
"timed_out":false,
"_shards":
{
"total":5,
"successful":5,
"skipped":0,
"failed":0
},
"hits":
{
"total":278,
"max_score":0.0,
"hits":[]
},
"aggregations":
{
"nombindiam":
{
"doc_count_error_upper_bound":0,
"sum_other_doc_count":0,
"buckets":
[
{"key":15,"doc_count":12},
{"key":20,"doc_count":24},
{"key":25,"doc_count":44}
]
}
}
}
如何獲取僅包含buckets節點的key屬性值的整數列表,如下所示:
List<int> myKeyValues= new List<int>() { 15, 20, 25 };
這是我到目前為止所得到的:
JObject json = JObject.Parse(response);
var myKeyValues = json["aggregations"]["nombindiam"]["buckets"].ToList();
您快到了,您只需要選擇鍵...
var myKeyValues = json["aggregations"]["nombindiam"]["buckets"]
.Select(x => x["key"])
.ToList();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.