Hi
I have an elastic query
get testaggregate/_search
{
"from":0,
"size":1000,
"query":{
"bool":{
"must":[
{"match": {"uCycleId": "111"}},
{"match": {"uTestId": "222"}},
{"match": {"TestResultSummarySubSubject.iSubjectId": 100}}
]
}
},
"aggs" : {
"filter" : { "match": { "TestResultSummarySubSubject.iSubjectId": 100 } },
"avg_testpoints" : { "avg" : { "field" : "TestResultSummarySubSubject.vResultAttribute.Result" } }
}
}
The data saved is like
{
"took": 9,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 2.8768208,
"hits": [
{
"_index": "testaggregate",
"_type": "testaggregate",
"_id": "1",
"_score": 2.8768208,
"_source": {
"uTestTokenId": "1",
"uCycleId": "111",
"uTestId": "222",
"TestResultSummary": [
{
"uExecutionId": "123",
"vResultAttribute": [
{
"PartiallyCorrectTasks": 4,
"Result": 7,
"TestObjectsCorrect": 16,
"TestMaxPoint": 31
}
]
}
],
"TestResultSummarySubSubject": [
{
"iSubjectId": 100,
"vResultAttribute": [
{
"PartiallyCorrectTasks": 4,
"Result": 10,
"TestObjectsCorrect": 16,
"TestMaxPoint": 31
}
]
},
{
"iSubjectId": 101,
"vResultAttribute": [
{
"PartiallyCorrectTasks": 4,
"Result": 11,
"TestObjectsCorrect": 16,
"TestMaxPoint": 31
}
]
},
{
"iSubjectId": 102,
"vResultAttribute": [
{
"PartiallyCorrectTasks": 4,
"Result": 12,
"TestObjectsCorrect": 16,
"TestMaxPoint": 31
}
]
},
{
"iSubjectId": 103,
"vResultAttribute": [
{
"PartiallyCorrectTasks": 4,
"Result": 13,
"TestObjectsCorrect": 16,
"TestMaxPoint": 31
}
]
}
]
}
},
{
"_index": "testaggregate",
"_type": "testaggregate",
"_id": "2",
"_score": 2.8768208,
"_source": {
"uTestTokenId": "2",
"uCycleId": "111",
"uTestId": "222",
"TestResultSummary": [
{
"uExecutionId": "121",
"vResultAttribute": [
{
"PartiallyCorrectTasks": 4,
"Result": 8.5,
"TestObjectsCorrect": 16,
"TestMaxPoint": 31
}
]
}
],
"TestResultSummarySubSubject": [
{
"iSubjectId": 100,
"vResultAttribute": [
{
"PartiallyCorrectTasks": 4,
"Result": 4,
"TestObjectsCorrect": 16,
"TestMaxPoint": 31
}
]
},
{
"iSubjectId": 101,
"vResultAttribute": [
{
"PartiallyCorrectTasks": 4,
"Result": 5,
"TestObjectsCorrect": 16,
"TestMaxPoint": 31
}
]
},
{
"iSubjectId": 102,
"vResultAttribute": [
{
"PartiallyCorrectTasks": 4,
"Result": 6,
"TestObjectsCorrect": 16,
"TestMaxPoint": 31
}
]
},
{
"iSubjectId": 103,
"vResultAttribute": [
{
"PartiallyCorrectTasks": 4,
"Result": 7,
"TestObjectsCorrect": 16,
"TestMaxPoint": 31
}
]
}
]
}
}
]
}
}
I need to find the average of TestResultSummarySubSubject.vResultAttribute.Result, for those having "TestResultSummarySubSubject.iSubjectId" = 100 in TestResultSummarySubSubject attribute
or
Average: group by iSubjectId
Above query is giving avarage for all without filter by iSubjectId
Thanks
Aneesh L