# Aggregation with multiple condition returning False values

**URL:** <https://discuss.elastic.co/t/aggregation-with-multiple-condition-returning-false-values/224020>\
**Category:** Elasticsearch\
**Created:** [March 18, 2020, 3:39am UTC](https://discuss.elastic.co/t/aggregation-with-multiple-condition-returning-false-values/224020 "2020-03-18T03:39:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BIRENDRA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/birendra/32/64625_2.png) [@BIRENDRA](https://discuss.elastic.co/u/BIRENDRA)\
**Post date:** [March 18, 2020, 3:39am UTC](https://discuss.elastic.co/t/aggregation-with-multiple-condition-returning-false-values/224020/1 "2020-03-18T03:39:39Z")

</div>

Hi Team,

I tried 2 ways to do this.

In one solution I am using 2 filter terms inside filter bool. That is shown below:

GET experiment\_air/\_search  
{  
"size": 5,  
"aggs": {  
"creations": {  
"filter": {  
"bool": {  
"filter": [  
{ "term" : { "refillProfileID.keyword": "ACT" } },  
{ "term" : { "act\_flag.keyword": "N" } }  
]  
}  
}  
}  
}  
}

In other solution I am using must with 2 terms inside filter bool. This is shown below:

GET experiment\_air/\_search  
{  
"aggs": {  
"creations": {  
"filter": {  
"bool": {  
"must":[  
{ "term" : { "refillProfileID.keyword": "ACT" }  
},  
{ "term" : { "act\_flag.keyword": "N" }  
}  
]  
}  
}  
}  
}  
}

My question is count of aggregation is coming same in both the queries. Only question is search query on aggregation give me false impression about its validity.

Attached is sample output as well.

{  
"took" : 43,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"skipped" : 0,  
"failed" : 0  
},  
"hits" : {  
"total" : {  
"value" : 10000,  
"relation" : "gte"  
},  
"max\_score" : 1.0,  
"hits" : [  
{  
"\_index" : "experiment\_air",  
"\_type" : "\_doc",  
"\_id" : "c1Un53ABBfwfMRwg0vOO",  
"\_score" : 1.0,  
"\_source" : {  
"refillType" : "2",  
"accountNumber" : "61434135105",  
"transactionAmount" : 30.0,  
"transactionCode" : "Standard",  
"air\_plan\_status" : "1060\_100\_N",  
"transactionType" : 0,  
"@timestamp" : "2019-12-01T15:30:43.000Z",  
"segmentationID" : "S003",  
"locationNumber" : null,  
"refillProfileID" : "100",  
"accountInformationBeforeRefill\_accountFlags" : "00000000",  
"voucherSerialNumber" : null,  
"air\_plan\_id" : "1060",  
"act\_flag" : "N",  
"accountInformationAfterRefill\_accountFlags" : "100"  
}  
},  
{  
"\_index" : "experiment\_air",  
"\_type" : "\_doc",  
"\_id" : "dFUn53ABBfwfMRwg0vOO",  
"\_score" : 1.0,  
"\_source" : {  
"refillType" : "2",  
"accountNumber" : "61434135105",  
"transactionAmount" : 30.0,  
"transactionCode" : "Standard",  
"air\_plan\_status" : "2111\_650\_N",  
"transactionType" : 0,  
"@timestamp" : "2019-12-29T15:09:01.000Z",  
"segmentationID" : "S003",  
"locationNumber" : null,  
"refillProfileID" : "650",  
"accountInformationBeforeRefill\_accountFlags" : "0000",  
"voucherSerialNumber" : null,  
"air\_plan\_id" : "2111",  
"act\_flag" : "N",  
"accountInformationAfterRefill\_accountFlags" : "100"  
}  
},  
{  
"\_index" : "experiment\_air",  
"\_type" : "\_doc",  
"\_id" : "dVUn53ABBfwfMRwg0vOO",  
"\_score" : 1.0,  
"\_source" : {  
"refillType" : "2",  
"accountNumber" : "61434135105",  
"transactionAmount" : 30.0,  
"transactionCode" : "Standard",  
"air\_plan\_status" : "180\_650\_Y",  
"transactionType" : 0,  
"@timestamp" : "2019-12-24T03:50:59.000Z",  
"segmentationID" : "S003",  
"locationNumber" : null,  
"refillProfileID" : "650",  
"accountInformationBeforeRefill\_accountFlags" : "00000000",  
"voucherSerialNumber" : null,  
"air\_plan\_id" : "180",  
"act\_flag" : "Y",  
"accountInformationAfterRefill\_accountFlags" : "10000000"  
}  
},  
{  
"\_index" : "experiment\_air",  
"\_type" : "\_doc",  
"\_id" : "dlUn53ABBfwfMRwg0vOO",  
"\_score" : 1.0,  
"\_source" : {  
"refillType" : "2",  
"accountNumber" : "61434135105",  
"transactionAmount" : 30.0,  
"transactionCode" : "Standard",  
"air\_plan\_status" : "2106\_298\_N",  
"transactionType" : 0,  
"@timestamp" : "2019-12-10T07:43:56.000Z",  
"segmentationID" : "S003",  
"locationNumber" : null,  
"refillProfileID" : "298",  
"accountInformationBeforeRefill\_accountFlags" : "10000000",  
"voucherSerialNumber" : null,  
"air\_plan\_id" : "2106",  
"act\_flag" : "N",  
"accountInformationAfterRefill\_accountFlags" : "10000000"  
}  
},  
{  
"\_index" : "experiment\_air",  
"\_type" : "\_doc",  
"\_id" : "d1Un53ABBfwfMRwg0vOO",  
"\_score" : 1.0,  
"\_source" : {  
"refillType" : "2",  
"accountNumber" : "61434135105",  
"transactionAmount" : 30.0,  
"transactionCode" : "Standard",  
"air\_plan\_status" : "2110\_650\_N",  
"transactionType" : 0,  
"@timestamp" : "2019-12-13T03:42:33.000Z",  
"segmentationID" : "S003",  
"locationNumber" : null,  
"refillProfileID" : "650",  
"accountInformationBeforeRefill\_accountFlags" : "10000000",  
"voucherSerialNumber" : null,  
"air\_plan\_id" : "2110",  
"act\_flag" : "N",  
"accountInformationAfterRefill\_accountFlags" : "00000000"  
}  
},  
{  
"\_index" : "experiment\_air",  
"\_type" : "\_doc",  
"\_id" : "eFUn53ABBfwfMRwg0vOO",  
"\_score" : 1.0,  
"\_source" : {  
"refillType" : "2",  
"accountNumber" : "61434135105",  
"transactionAmount" : 30.0,  
"transactionCode" : "Standard",  
"air\_plan\_status" : "1095\_468\_Y",  
"transactionType" : 0,  
"@timestamp" : "2019-12-07T10:38:03.000Z",  
"segmentationID" : "S003",  
"locationNumber" : null,  
"refillProfileID" : "468",  
"accountInformationBeforeRefill\_accountFlags" : "00000000",  
"voucherSerialNumber" : null,  
"air\_plan\_id" : "1095",  
"act\_flag" : "Y",  
"accountInformationAfterRefill\_accountFlags" : "10000000"  
}  
},  
{  
"\_index" : "experiment\_air",  
"\_type" : "\_doc",  
"\_id" : "eVUn53ABBfwfMRwg0vOO",  
"\_score" : 1.0,  
"\_source" : {  
"refillType" : "2",  
"accountNumber" : "61434135105",  
"transactionAmount" : 30.0,  
"transactionCode" : "Standard",  
"air\_plan\_status" : "1014\_ALL\_N",  
"transactionType" : 0,  
"@timestamp" : "2019-12-10T15:12:46.000Z",  
"segmentationID" : "S003",  
"locationNumber" : null,  
"refillProfileID" : "ALL",  
"accountInformationBeforeRefill\_accountFlags" : "0000",  
"voucherSerialNumber" : null,  
"air\_plan\_id" : "1014",  
"act\_flag" : "N",  
"accountInformationAfterRefill\_accountFlags" : "00000000"  
}  
},  
{  
"\_index" : "experiment\_air",  
"\_type" : "\_doc",  
"\_id" : "elUn53ABBfwfMRwg0vOO",  
"\_score" : 1.0,  
"\_source" : {  
"refillType" : "2",  
"accountNumber" : "61434135105",  
"transactionAmount" : 30.0,  
"transactionCode" : "Standard",  
"air\_plan\_status" : "1015\_650\_N",  
"transactionType" : 0,  
"@timestamp" : "2019-12-09T11:06:44.000Z",  
"segmentationID" : "S003",  
"locationNumber" : null,  
"refillProfileID" : "650",  
"accountInformationBeforeRefill\_accountFlags" : "0000",  
"voucherSerialNumber" : null,  
"air\_plan\_id" : "1015",  
"act\_flag" : "N",  
"accountInformationAfterRefill\_accountFlags" : "00000000"  
}  
},  
{  
"\_index" : "experiment\_air",  
"\_type" : "\_doc",  
"\_id" : "e1Un53ABBfwfMRwg0vOO",  
"\_score" : 1.0,  
"\_source" : {  
"refillType" : "2",  
"accountNumber" : "61434135105",  
"transactionAmount" : 30.0,  
"transactionCode" : "Standard",  
"air\_plan\_status" : "2111\_120\_N",  
"transactionType" : 0,  
"@timestamp" : "2019-12-19T16:45:58.000Z",  
"segmentationID" : "S003",  
"locationNumber" : null,  
"refillProfileID" : "120",  
"accountInformationBeforeRefill\_accountFlags" : "0000",  
"voucherSerialNumber" : null,  
"air\_plan\_id" : "2111",  
"act\_flag" : "N",  
"accountInformationAfterRefill\_accountFlags" : "100"  
}  
},  
{  
"\_index" : "experiment\_air",  
"\_type" : "\_doc",  
"\_id" : "fFUn53ABBfwfMRwg0vOO",  
"\_score" : 1.0,  
"\_source" : {  
"refillType" : "2",  
"accountNumber" : "61434135105",  
"transactionAmount" : 30.0,  
"transactionCode" : "Standard",  
"air\_plan\_status" : "1014\_ACT\_N",  
"transactionType" : 0,  
"@timestamp" : "2019-12-01T02:01:03.000Z",  
"segmentationID" : "S003",  
"locationNumber" : null,  
"refillProfileID" : "ACT",  
"accountInformationBeforeRefill\_accountFlags" : "0000",  
"voucherSerialNumber" : null,  
"air\_plan\_id" : "1014",  
"act\_flag" : "N",  
"accountInformationAfterRefill\_accountFlags" : "10000000"  
}  
}  
]  
},  
"aggregations" : {  
"creations" : {  
"doc\_count" : 33365  
}  
}  
}

My question is why, **refillProfileID** and **act\_flag** whose value is not '2120' and 'N' respectively are coming in this search query result.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 15, 2020, 3:39am UTC](https://discuss.elastic.co/t/aggregation-with-multiple-condition-returning-false-values/224020/2 "2020-04-15T03:39:42Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
