Elasticsearch is not intended for this type of functionality, you may be better served looking into more efficient ways to setup your project to be able to hand this, however there are some tools which can allow you to shoehorn in this form of a query.
While the basic query syntax doesn't encompass comparing fields, Scripts can allow you work around this.
Here is an example of a script using NEST:
.Query(q=>q
.Term(w => w.MatchAll())
.Filter(s => s.Script(sf => sf.Script("doc['mails.field_A'].value == doc['mails.field_B'].value"))
)
Here is an example of a script without using NEST:
{
"query": {
"filtered": {
"filter": {
"script": {
"script": "doc['mails.field_A'].value == doc['mails.field_B'].value"
}
}
}
}
}
This will function provided script.disable_dynamic is set to false. Some security issues can arise.