I want the size of an array of objects ('breaches' here) which is present in each document to be returned along with the fields present in the document once the query is executed. How can I do this? Below is my document structure and mapping. I tried with inline script but did not get success. I want name, age, email, contact, total number of breaches to be returned for each document.
{
"age": 45,
"email": "",
"contact": 9899999999,
"name": "xyx",
"breaches": [{
"_id": "5e833cae56cd2e0011ee8e4a",
"citizen": "5e82e0f5fb4f240012fa9737",
"breachType": "location_disabled",
"timestamp": "2020-03-31T12:50:52.828Z",
"division": null,
"createdAt": "2020-03-31T12:50:54.371Z"
}]
}
Mapping
{
"properties": {
"age": {
"type": "long"
},
"email": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"contact": {
"type": "long"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"breaches": {
"type": "nested",
"properties": {
"_id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"breachType": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"citizen": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"createdAt": {
"type": "date"
},
"division": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}