Finding errors related to transactions

Elasticsearch version:
6.8.4
APM Server version:
7.6.0
APM Agent language and version:
Java agent - 1.15

Original install method (e.g. download page, yum, deb, from source, etc.) and version:
Download package

Fresh install or upgraded from other version?
Upgraded

Currently, we can link the error document to a particular transaction with the transaction.id field in the error document. However, I do not see any way to link the error from the transaction document.
What we would like to achieve is a query which will get us the error (or even acknowledge that there was an error) from the transaction index. Something similar to the span_count field in the transaction document.

Is there a way we can achieve this?

Thanks for the feedback!
Please describe you use case in more details (what question you want to get answered).
In case you are not aware, there is a transaction.result field, that doesn't answer exactly what you are asking, but may be useful if you are looking for transactions ending erroneously.

Thanks for your reply, Eyal!

The exceptions thrown in our application are not specific to the status code (which is essentially the data in transaction.result). We find that not all erroneous status codes result in an error event.
What we would like to do is get the number of errors grouped by the transaction name.
A single query that will get us the number of errors where transaction.name == *
I am aware that this can be achieved with a two step query, but just confirming that there isn't a simpler way to do this.

It would be interesting if you could point us to exact scenarios where that is the case.

Unfortunately, given our schema and what you need, I believe this will be the way to go.

Are you interested in the exact number of errors or would a simple boolean flag at the transaction level be enough for you? Such a flag could indeed be quite useful to calculate the error rate of transactions.

Even a simple boolean flag will help quite a bit.
Is there a way we can contribute to the java and python agent to get this flag?
Any help in this direction would be great!

As an example, in a python application, an uncaught syntax error will throw a 500 Internal Server error, which will trigger an error event.
But in somecases, we catch the exception and return an HTTP Response with 500 status code. In these cases, an error event is not triggered.