我是Elastic Search的新手,我的任务是在.Net项目中对少数功能进行单元测试 . 函数使用弹性查询,我试图通过使用InMemeory方法来模拟它
以下是Json的回复 .
{
"took" : 76,
"timed_out" : false,
"hits" :
{
"total" : 1899,
"max_score" : 0,
},
"aggregations":
{
"jobs" :
{
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" :
{
"key" : "XYZ",
"doc_count" : 1800,
"runs" :
{
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" :
{
"key" : 49127,
"doc_count" : 3,
"groupby_runs" :
{
"hits" :
{
"total" : 3,
"max_score" : 0,
"hits" : []
{
{
"_type" : "testdocument" ,
"_index" : "test_docs-2018.10.08",
"_id" : "1-1-49127-37" ,
"_score" : 2,
"_source" :
{
"timeStamp" : "2018-10-08T08 :47 :18.781+05 :30" ,
"isPassed" : true,
"runSourceDuration : 6,
"runId" : 49127,
"runSourceName" : "XYZ" ,
"isReleaseValidation" : false
},
"sort" :1538968638781
},
{
"_type" : "test_docs-2018.10.08",
"_index" : "testdocument" ,
"_id" : "1-1-49127-39" ,
"_score" : 2,
"_source" :
{
"timeStamp " : "2018-10-08T08 :47 :18.781+05 :30" ,
"isPassed " : true,
"runSourceDuration " : 6,
"runId" : 49127,
"runSourceName" : "XYZ" ,
"isReleaseValidation" : false
},
"sort" :1538968638781
},
{
"_type" : "test_docs-2018.10.08",
"_index" "testdocument" ,
"_id" : "1-1-49127-47" ,
"_score" : 2,
"_source" :
{
"timeStamp " : "2018-10-08T08 :47 :18.781+05 :30" ,
"isPassed " : true,
"runSourceDuration " : 6,
"runId" : 49127,
"runSourceName" : "XYZ" ,
"isReleaseValidation" : false
},
"sort" :1538968638781
}
}
}
}
}
}
}
}
}
};
我试图将其转换为匿名嵌套(C#)对象 . 但它没有给我确切的预期结果 .
var response = new
{
took = 76,
timed_out = false,
hits = new
{
total = 1899,
max_score = 0,
},
aggregations = new
{
jobs = new
{
doc_count_error_upper_bound = 0,
sum_other_doc_count = 0,
Buckets = new
{
key = "XYZ",
doc_count = 1800,
runs = new
{
doc_count_error_upper_bound = 0,
sum_other_doc_count = 0,
Buckets = new
{
key = 49127,
doc_count = 3,
groupby_runs = new
{
hits = new
{
total = 3,
max_score = 0,
hits = new[]
{
new{
_index = "test_report_docs-2018.10.08",
_type = "testreportdocument" ,
_id = "1-1-49127-37" ,
_score = 2,
_source = new
{
timeStamp = "2018-10-08T08 =47 =18.781+05 =30" ,
isPassed = true,
runSourceDuration = 6,
runId = 49127,
runSourceName = "XYZ" ,
isReleaseValidation = false
},
sort =1538968638781
},
new{
_index = "test_docs-2018.10.08",
_type = "testdocument" ,
_id = "1-1-49127-39" ,
_score = 2,
_source = new
{
timeStamp = "2018-10-08T08 =47 =18.781+05 =30" ,
isPassed = true,
runSourceDuration = 6,
runId = 49127,
runSourceName = "XYZ" ,
isReleaseValidation = false
},
sort =1538968638781
},
new{
_index = "test_docs-2018.10.08",
_type = "testdocument" ,
_id = "1-1-49127-47" ,
_score = 2,
_source = new
{
timeStamp = "2018-10-08T08 =47 =18.781+05 =30" ,
isPassed = true,
runSourceDuration = 6,
runId = 491,
runSourceName = "XYZ" ,
isReleaseValidation = false
},
sort =1538968638781
}
}
}
}
}
}
}
}
}
};
var response = service.Search<TD>(new GetQuery().Query());
我收到Bucket.count = 0和var jobs = response.Aggs.Terms(“jobs”)返回null . 你能帮我纠正一下匿名对象吗?