Hi there ,
Sorry for late response.
Here for your information :
my records are as below:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 5,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "sample",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"jobId" : 1,
"title" : "first title",
"country" : "nepal",
"status" : "active",
"overDue" : "true"
}
},
{
"_index" : "sample",
"_id" : "YupBN4EBlAA2g3ulx4eO",
"_score" : 1.0,
"_source" : {
"jobId" : 2,
"title" : "second title",
"country" : "india",
"status" : "active",
"overDue" : "true"
}
},
{
"_index" : "sample",
"_id" : "Y-pCN4EBlAA2g3ulJofl",
"_score" : 1.0,
"_source" : {
"jobId" : 3,
"title" : "third title",
"country" : "india",
"status" : "active",
"overDue" : "false"
}
},
{
"_index" : "sample",
"_id" : "ZOpCN4EBlAA2g3ulx4cQ",
"_score" : 1.0,
"_source" : {
"jobId" : 5,
"title" : "fifth title",
"country" : "india",
"status" : "cancelled",
"overDue" : "true"
}
},
{
"_index" : "sample",
"_id" : "DzRCN4EB43mQOuzybfUU",
"_score" : 1.0,
"_source" : {
"jobId" : 4,
"title" : "fourth title",
"country" : "india",
"status" : "cancelled",
"overDue" : "false"
}
}
]
}
}
- so as per my view here you need count for active ,cancelled status count and overDue count
so my solution is as below:
GET /sample/_search
{
"size": 1,
"query": {
"bool": {
"must": [
{
"match": {
"country": "india"
}
}
]
}
},
"aggs": {
"status": {
"terms": {
"field": "status.keyword",
"size": 10
}
},
"overDue": {
"terms": {
"field": "overDue.keyword",
"size": 10
}
}
}
}
Output will be like
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 0.20763937,
"hits" : [
{
"_index" : "sample",
"_id" : "YupBN4EBlAA2g3ulx4eO",
"_score" : 0.20763937,
"_source" : {
"jobId" : 2,
"title" : "second title",
"country" : "india",
"status" : "active",
"overDue" : "true"
}
}
]
},
"aggregations" : {
"overDue" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "false",
"doc_count" : 2
},
{
"key" : "true",
"doc_count" : 2
}
]
},
"status" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "active",
"doc_count" : 2
},
{
"key" : "cancelled",
"doc_count" : 2
}
]
}
}
}
i hope this help you out if not feel free to replay.
Thank you