# How can I select a test document which state has changed from "passed" to "failed"

**URL:** <https://discuss.elastic.co/t/how-can-i-select-a-test-document-which-state-has-changed-from-passed-to-failed/167165>\
**Category:** Elasticsearch\
**Created:** [February 5, 2019, 5:22pm UTC](https://discuss.elastic.co/t/how-can-i-select-a-test-document-which-state-has-changed-from-passed-to-failed/167165 "2019-02-05T17:22:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrei1610399](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@andrei1610399](https://discuss.elastic.co/u/andrei1610399)\
**Post date:** [February 5, 2019, 5:22pm UTC](https://discuss.elastic.co/t/how-can-i-select-a-test-document-which-state-has-changed-from-passed-to-failed/167165/1 "2019-02-05T17:22:49Z")

</div>

I have test documents like one below:  
test\_reslulsts:  
{  
"report\_id":"my\_report\_1",  
"test\_name":"some\_test\_name\_123",  
"status":"passed"  
"parent\_details":  
{  
"parent\_id":"154865976079",  
"run\_tag":125  
}  
}

I need to select all the test\_results that were passing for given "parent\_id" and failing for another "parent\_id".

I am using composite aggregation now, but it returns me only the tests whose status have changed.  
I want to specify how the status was changed (for example from "passed" to "failed") and get all such documents not just their ids.

GET test\_results/\_search  
{"query":  
{"bool": {"must": [  
{"terms": { "test\_reslulsts.parent\_id": ["154865976079","154881593370"]}}]  
}},  
"aggs" : {  
"my\_buckets": {  
"composite" : { "size": 100,  
"sources" : [  
{ "test\_name": { "terms" : { "field": "name" } } },  
{ "test\_result": { "terms" : { "field": "status" } } }  
],  
"after": {  
"test\_name": "some\_test\_name\_1234",  
"test\_result": "failed"  
}  
},  
"aggs": {  
"filter": {  
"bucket\_selector": {  
"buckets\_path": {  
"doc\_count": "\_count"  
},  
"script": "params.doc\_count == 1"  
}  
}  
}}  
},  
"size": 0  
}

---

<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:** [March 5, 2019, 5:22pm UTC](https://discuss.elastic.co/t/how-can-i-select-a-test-document-which-state-has-changed-from-passed-to-failed/167165/2 "2019-03-05T17:22:50Z")

</div>

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