How to chain two queries so the result of one becomes one end of a date range in the other

I'm using Kibana to track my test passes. My leadership just asked me to add a metric that shows how long a particular repository has been failing test passes for. I figured out how to make a relative date value. But I can't find the right document to show the date of. I really want my metric to show the relative date of the first failing test pass. I think what I really want to do is first search for all the passing test passes, returning only the most recent passing test pass, and have the date from that passing test pass be the lower range of a search for all failing tests between now and that passing test pass. Is there a way to chain queries together like that?

I ended up writing a script to do the queries before I upload my data to ES. I just added a new field for that value to my index, and compute it in the script.