This recreation steps gives my exact count match from array
DELETE index001
PUT index001
{
"mappings": {
"Process": {
"properties": {
"ProcessInstance": {
"type": "nested"
}
}
}
}
}
PUT index001/Process/1
{
"Name": "PrTest",
"Step": "Second",
"_status": "InProgress",
"ProcessInstance":
[
{
"_status": "Completed",
"AssignedTo":
[
{
"_id": "sangeeth",
"Name": "sangeeth",
"Kind": "User"
}
]
},
{
"_status": "InProgress",
"AssignedTo":
[
{
"_id": "sangeeth",
"Name": "sangeeth",
"Kind": "User"
}
]
}
]
}
GET index001/_search
{
"size": 0,
"query": {
"bool": {
"must": {
"match": {
"_status.keyword": "InProgress"
}
},
"filter": {
"nested": {
"path": "ProcessInstance",
"query": {
"bool":{"must":[{
"match": {
"ProcessInstance.AssignedTo._id": "sangeeth"
}
},
{
"match": {
"ProcessInstance._status.keyword": "InProgress"
}
}]
}
}
}
}
}
},
"aggs": {
"nested_events": {
"nested": {
"path": "ProcessInstance"
},
"aggs": {
"filtered_events": {
"filter": {
"bool":{"must":[{
"term": {
"ProcessInstance.AssignedTo._id": "sangeeth"
}
},
{
"term": {
"ProcessInstance._status.keyword": "InProgress"
}
}]
}
}
}
}
}
}
}
Returns:
{
....
"aggregations": {
"nested_events": {
"doc_count": 2,
"filtered_events": {
"doc_count": 1
}
}
}
}
Count looks fine now.
Is there any way to return only the matched item as result hits?
Expected output:
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.2876821,
"hits": [
{
"_index": "index001",
"_type": "Process",
"_id": "2",
"_score": 0.2876821,
"_source": {
"Name": "PrTest",
"Step": "Second",
"_status": "InProgress",
"ProcessInstance": [
{
"_status": "InProgress",
"AssignedTo": [
{
"_id": "sangeeth",
"Name": "sangeeth",
"Kind": "User"
}
]
}
]
}
}
]
},
"aggregations": {
"nested_events": {
"doc_count": 2,
"filtered_events": {
"doc_count": 1
}
}
}
}